diff --git a/Makefile b/Makefile index 66ecc5da8..e4784a746 100755 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ # find all verifiable packages. # XXX: explore a better way that doesn't need multiple 'find' -PKGS := `find . -mindepth 1 -maxdepth 1 -type d -name '*' | grep -vE '/\..*$\|Godeps|examples|docs|scripts|mgmtfn|bin|contrib'` -PKGS += `find . -mindepth 2 -maxdepth 2 -type d -name '*'| grep -vE '/\..*$\|Godeps|examples|docs|scripts|bin|contrib'` +PKGS := `find . -mindepth 1 -maxdepth 1 -type d -name '*' | grep -vE '/\..*$\|Godeps|examples|docs|scripts|mgmtfn|bin|demo'` +PKGS += `find . -mindepth 2 -maxdepth 2 -type d -name '*'| grep -vE '/\..*$\|Godeps|examples|docs|scripts|bin|demo'` TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contivk8s/ HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi` HOST_GOROOT := `go env GOROOT` @@ -40,7 +40,7 @@ run-build: deps checks clean cd ${GOPATH}/src/github.com/contiv/netplugin && version/generate_version ${USE_RELEASE} && \ cd $(GOPATH)/src/github.com/contiv/netplugin && \ godep go install -v $(TO_BUILD) && \ - sudo cp contrib/completion/bash/netctl /etc/bash_completion.d/netctl + sudo cp scripts/contrib/completion/bash/netctl /etc/bash_completion.d/netctl build: make start @@ -62,13 +62,23 @@ start: update #kubernetes demo targets k8s-cluster: - cd mgmtfn/k8splugin/contivk8s/vagrant && ./setup_cluster.sh + cd demo/k8s/ && ./setup_cluster.sh k8s-demo: - cd mgmtfn/k8splugin/contivk8s/vagrant && ./copy_demo.sh + cd demo/k8s/ && ./copy_demo.sh k8s-demo-start: - cd mgmtfn/k8splugin/contivk8s/vagrant && ./restart_cluster.sh && vagrant ssh k8master + cd demo/k8s/ && ./restart_cluster.sh && vagrant ssh k8master k8s-destroy: - cd mgmtfn/k8splugin/contivk8s/vagrant && vagrant destroy -f + cd demo/k8s/ && vagrant destroy -f + +# Mesos demo targets +mesos-docker-demo: + cd demo/mesos-docker && vagrant up + cd demo/mesos-docker && vagrant ssh node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"' + cd demo/mesos-docker && vagrant ssh node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && ./scripts/python/startPlugin.py -nodes 192.168.33.10,192.168.33.11"' + +mesos-docker-destroy: + cd demo/mesos-docker && vagrant destroy -f + demo-centos: CONTIV_NODE_OS=centos make demo @@ -79,11 +89,7 @@ stop: demo: vagrant up vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"' - vagrant ssh netplugin-node1 -c 'nohup bash -lc "sudo /opt/gopath/bin/netplugin -plugin-mode docker -vlan-if eth2 2>&1> /tmp/netplugin.log &"' - vagrant ssh netplugin-node2 -c 'nohup bash -lc "sudo /opt/gopath/bin/netplugin -plugin-mode docker -vlan-if eth2 2>&1> /tmp/netplugin.log &"' - sleep 10 - vagrant ssh netplugin-node1 -c 'nohup bash -lc "/opt/gopath/bin/netmaster 2>&1> /tmp/netmaster.log &"' - sleep 10 + vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-restart"' ssh: @vagrant ssh netplugin-node1 -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin/ && bash"' || echo 'Please run "make demo"' @@ -129,11 +135,11 @@ host-restart: @echo dev: restarting services... cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./startPlugin.py -nodes ${CLUSTER_NODE_IPS} -only-tar: +only-tar: tar: clean-tar build @cat ${GOPATH}/src/github.com/contiv/netplugin/version/version_gen.go | grep versionStr | cut -f 4 -d " " | tr -d \" > $(VERSION_FILE) - @tar -jcf $(TAR_FILE) -C $(GOPATH)/src/github.com/contiv/netplugin/bin netplugin netmaster netctl contivk8s -C $(GOPATH)/src/github.com/contiv/netplugin contrib/completion/bash/netctl + @tar -jcf $(TAR_FILE) -C $(GOPATH)/src/github.com/contiv/netplugin/bin netplugin netmaster netctl contivk8s -C $(GOPATH)/src/github.com/contiv/netplugin/scripts contrib/completion/bash/netctl clean-tar: @rm -f $(TAR_LOC)/*.$(TAR_EXT) diff --git a/README.md b/README.md index 1b9cfbd7c..792cc5b98 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ $ vagrant ssh netplugin-node1 #### Step 2: Create a network ``` -$ netctl net create contiv-net --subnet=20.1.1.0/24 --gateway=20.1.1.254 --pkt-tag=1001 +$ netctl net create contiv-net --subnet=20.1.1.0/24 ``` #### Step 3: Run your containers and enjoy the networking! diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/Vagrantfile b/demo/k8s/Vagrantfile similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/Vagrantfile rename to demo/k8s/Vagrantfile diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/cluster_defs.json b/demo/k8s/cluster_defs.json similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/cluster_defs.json rename to demo/k8s/cluster_defs.json diff --git a/demo/k8s/copy_demo.sh b/demo/k8s/copy_demo.sh new file mode 100755 index 000000000..7c7a645e4 --- /dev/null +++ b/demo/k8s/copy_demo.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# run ansible +ansible-playbook -i .contiv_k8s_inventory ../../../contrib/ansible/cluster.yml --tags "contiv_demo" -e "networking=contiv" diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/defaultnet-busybox1.yaml b/demo/k8s/export/defaultnet-busybox1.yaml similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/defaultnet-busybox1.yaml rename to demo/k8s/export/defaultnet-busybox1.yaml diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/defaultnet-busybox2.yaml b/demo/k8s/export/defaultnet-busybox2.yaml similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/defaultnet-busybox2.yaml rename to demo/k8s/export/defaultnet-busybox2.yaml diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/nc-busybox/Dockerfile.nc-busybox b/demo/k8s/export/nc-busybox/Dockerfile.nc-busybox similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/nc-busybox/Dockerfile.nc-busybox rename to demo/k8s/export/nc-busybox/Dockerfile.nc-busybox diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/nc-busybox/nc_loop.sh b/demo/k8s/export/nc-busybox/nc_loop.sh similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/nc-busybox/nc_loop.sh rename to demo/k8s/export/nc-busybox/nc_loop.sh diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/noping-busybox.yaml b/demo/k8s/export/noping-busybox.yaml similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/noping-busybox.yaml rename to demo/k8s/export/noping-busybox.yaml diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/pingme-busybox.yaml b/demo/k8s/export/pingme-busybox.yaml similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/pingme-busybox.yaml rename to demo/k8s/export/pingme-busybox.yaml diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/pocnet-busybox.yaml b/demo/k8s/export/pocnet-busybox.yaml similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/pocnet-busybox.yaml rename to demo/k8s/export/pocnet-busybox.yaml diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/export/policy.sh b/demo/k8s/export/policy.sh similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/export/policy.sh rename to demo/k8s/export/policy.sh diff --git a/demo/k8s/restart_cluster.sh b/demo/k8s/restart_cluster.sh new file mode 100755 index 000000000..857a88828 --- /dev/null +++ b/demo/k8s/restart_cluster.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +top_dir=$(git rev-parse --show-toplevel | sed 's|/[^/]*$||') +# run ansible +ansible-playbook -i .contiv_k8s_inventory ../../../contrib/ansible/cluster.yml --tags "contiv_restart" -e "networking=contiv contiv_bin_path=$top_dir/contiv_bin" diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/setup_cluster.sh b/demo/k8s/setup_cluster.sh similarity index 87% rename from mgmtfn/k8splugin/contivk8s/vagrant/setup_cluster.sh rename to demo/k8s/setup_cluster.sh index ded5156d2..310101c3e 100755 --- a/mgmtfn/k8splugin/contivk8s/vagrant/setup_cluster.sh +++ b/demo/k8s/setup_cluster.sh @@ -11,7 +11,7 @@ function GetKubernetes { rm -rf $top_dir/k8s-$k8sVer/kubernetes rm -rf $top_dir/k8s-$k8sVer/bin else - cd $top_dir/k8s-$k8sVer + cd $top_dir/k8s-$k8sVer wget https://github.com/kubernetes/kubernetes/releases/download/$k8sVer/kubernetes.tar.gz fi @@ -76,4 +76,4 @@ vagrant up ./vagrant_cluster.py # run ansible -ansible-playbook -i .contiv_k8s_inventory ../../../../../contrib/ansible/cluster.yml --skip-tags "contiv_restart,ovs_install" -e "networking=contiv localBuildOutput=$top_dir/k8s-$k8sVer/kubernetes/server/bin contiv_bin_path=$top_dir/contiv_bin" +ansible-playbook -i .contiv_k8s_inventory ../../../contrib/ansible/cluster.yml --skip-tags "contiv_restart,ovs_install" -e "networking=contiv localBuildOutput=$top_dir/k8s-$k8sVer/kubernetes/server/bin contiv_bin_path=$top_dir/contiv_bin" diff --git a/mgmtfn/k8splugin/contivk8s/vagrant/vagrant_cluster.py b/demo/k8s/vagrant_cluster.py similarity index 100% rename from mgmtfn/k8splugin/contivk8s/vagrant/vagrant_cluster.py rename to demo/k8s/vagrant_cluster.py diff --git a/demo/mesos-docker/README.md b/demo/mesos-docker/README.md new file mode 100644 index 000000000..a9b138115 --- /dev/null +++ b/demo/mesos-docker/README.md @@ -0,0 +1,78 @@ +# Netplugin with Mesos Marathon + +This document explains how to use Netplugin with Mesos Marathon. Currently, netplugin supports docker containerizer with Mesos Marathon. + +## Getting started with Vagrant VMs +### Prerequisits +- Virtualbox 5.0.2 or higher +- Vagrant 1.7.4 or higher +- ansible 1.9.4 or higher + +### Step 1: Bring up the vagrant VMs + +``` +$ git clone https://github.com/contiv/netplugin +$ cd netplugin +$ make mesos-docker-demo +``` + +This will bring up a two node Vagrant setup with Mesos, Marathon and docker. +Bringing up vagrant VMs and provisioning them can take few minutes to complete since it needs to download the VM images and mesos/marathon binaries. Please be patient. +This will also build netplugin binaries and start them on both VMs + + +### Step 2: Login to a VM and Create a network + +``` +$ cd demo/mesos-docker; vagrant ssh node1 + +$ netctl net create contiv -subnet 10.1.1.0/24 +``` + +This will create a network called `contiv`. Containers can be launched in this network. + +### Step 3: Launch containers + +`docker.json` file in mgmtfn/mesos-docker directory has an example marathon app definition. + +``` + + "container": { + "type": "DOCKER", + "docker": { + "image": "libmesos/ubuntu", + "parameters": [ { "key": "net", "value": "contiv" } ] + } + }, + "id": "ubuntu", + "instances": 2, + "constraints": [ ["hostname", "UNIQUE", ""] ], + "cpus": 1, + "mem": 128, + "uris": [], + "cmd": "while sleep 10; do date -u +%T; done" +} +``` + +This example application definition launches two ubuntu containers with a constraint that both containers be spread on different hosts. +Note that there is a special `net` parameter used in this specification `"parameters": [ { "key": "net", "value": "contiv" } ]`. This tells docker to launch the application in contiv network that we created in step 3. + +You can launch this application using following command + +``` +$ ./launch.sh docker.json +``` + +Launching the container can take few minutes depending on how long it takes to pull the image. +Once its launched, you should be able to see the containers using docker commands + +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +2a68fed77d5a libmesos/ubuntu "/bin/sh -c 'while sl" About an hour ago Up About an hour mesos-cce1c91f-65fb-457d-99af-5fdd4af14f16-S1.da634e3c-1fde-479a-b100-c61a498bcbe7 + ``` + +## Notes + + 1. Mesos and Marathon ports are port-mapped from vagrant VM to host machine. You can access them by logging into localhost:5050 and localhost:8080 respectively. + 2. Netmaster web-ui is port-mapped to port 9090 on the host machine diff --git a/demo/mesos-docker/Vagrantfile b/demo/mesos-docker/Vagrantfile new file mode 100644 index 000000000..4d85c4be4 --- /dev/null +++ b/demo/mesos-docker/Vagrantfile @@ -0,0 +1,190 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +require 'fileutils' + +# netplugin_synced_gopath="/opt/golang" +gopath_folder="/opt/gopath" + +# Get env setting for http proxies +host_env = { } +host_env["no_proxy"] = "192.168.2.10,192.168.2.11,127.0.0.1,localhost,netmaster" +if ENV['CONTIV_ENV'] then + ENV['CONTIV_ENV'].split(" ").each do |env| + e = env.split("=") + host_env[e[0]]=e[1] + end +end + +if ENV["http_proxy"] + host_env["HTTP_PROXY"] = host_env["http_proxy"] = ENV["http_proxy"] + host_env["HTTPS_PROXY"] = host_env["https_proxy"] = ENV["https_proxy"] +end + +ansible_extra_vars = { + "env" => host_env, + "validate_certs" => "no", +} + +ANSIBLE_GROUPS = { + "master" => ["node1"], + "nodes" => ["node2"], + "all_groups:children" => ["master, ""nodes"] + } + +provision_common = <