-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use docker containers as hosts for testing netplugin #37
Changes from 7 commits
ab59f37
db35897
11a861c
de6aea7
1fcea28
352cd59
e1548b5
53a1652
922bbdc
02d07fc
976b00c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
The multi node container networking can now be tested on a single VM by running docker inside docker. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - suggest removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
https://blog.docker.com/2013/09/docker-can-now-run-within-docker/ | ||
|
||
The outside docker containers act like physical hosts in our test and are connected using a standard linux bridge. Inside each "host container" we run a namespaced instance of docker, OVS , etcd and netplugin instance. One can now launch containers from within each "host containers" and use netplugin networking to connect them. | ||
|
||
Prerequisites | ||
------------- | ||
The following needs to be installed on the host machine | ||
1. Docker | ||
2. nsenter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave a pointer to nsenter repo so someone can get going) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
3. Linux bridge | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linux bridge is included in linux if I am not mistaken, do you mean brutils? It may be a good idea to give an example that on Ubuntu one can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
Step to launch docker hosts are : | ||
-------------------------------- | ||
``` | ||
cd $GOPATH/src/github.com/contiv/netplugin | ||
CONTINV_NODES=2 make start-dockerdemo | ||
``` | ||
|
||
This will start CONTIV_NODES number of containers with docker image called ubuntu_netplugin which is just ubuntu image with docker, etcd and ovs installed. | ||
|
||
Now start a shell within any of the "host containers" using following convenient wrapper around nsenter : | ||
``` | ||
docker-sh netplugin-node<x> | ||
``` | ||
|
||
Start netplugin, post netplugin config and launch containers inside the "host containers" the same way you do on VMs. | ||
Note : currently the demo is working only if config is posted before containers are started .. need to debug why the reverse is not working. | ||
|
||
To cleanup all the docker hosts and the virtual interfaces created do | ||
``` | ||
make cleanup-dockerdemo | ||
``` | ||
|
||
Example for testing TwoHostMultiVlan you can do : | ||
|
||
1. Launch the two host containers | ||
|
||
``` | ||
export CONTIV_NODES=2 | ||
make start-dockerdemo | ||
``` | ||
|
||
2. Load the netplugin configuration | ||
``` | ||
docker-sh netplugin-node1 | ||
/netplugin/bin/netdcli -cfg /netplugin/examples/two_hosts_multiple_vlans_nets.json | ||
``` | ||
|
||
3. Launch container1 on host1 | ||
|
||
``` | ||
docker-sh netplugin-node1 | ||
docker run -it --name=myContainer1 --hostname=myContainer1 ubuntu /bin/bash | ||
``` | ||
|
||
4. Launch container3 on host2 | ||
|
||
``` | ||
docker-sh netplugin-node2 | ||
docker run -it --name=myContainer3 --hostname=myContainer1 ubuntu /bin/bash | ||
``` | ||
|
||
5. Test connectivity between the containers using ping. Go to the shell for container1 | ||
``` | ||
root@myContainer1:/# ping -c3 11.1.2.2 | ||
PING 11.1.2.2 (11.1.2.2) 56(84) bytes of data. | ||
64 bytes from 11.1.2.2: icmp_seq=1 ttl=64 time=3.15 ms | ||
64 bytes from 11.1.2.2: icmp_seq=2 ttl=64 time=1.36 ms | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ echo "Checking gofmt..." | |
fmtRes=$(gofmt -l ./) | ||
if [ -n "${fmtRes}" ]; then | ||
echo -e "gofmt checking failed:\n${fmtRes}" | ||
exit 1 | ||
# exit 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why exit with '0' code when go-fmt fails? Any reason for this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry that got in by mistake. Reverted. Btw if i do a make build two times without clean i get gofmt errors. |
||
fi | ||
|
||
echo "All checks passed!!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
#!/bin/bash | ||
|
||
num_nodes=1 | ||
if [ -z "$CONTIV_NODES" ]; | ||
then | ||
num_nodes=1 | ||
else | ||
num_nodes=$CONTIV_NODES | ||
fi | ||
echo $num_nodes | ||
|
||
for i in `seq 1 $num_nodes`; | ||
do | ||
hostname="netplugin-node$i" | ||
echo "Cleaning $hostname" | ||
sudo docker exec $hostname service docker stop | ||
sudo docker rm -f $hostname | ||
sudo ip link delete $i-ext | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
for i in `seq 9 20`; | ||
do | ||
sudo /bin/mknod -m640 /dev/loop$i b 7 $i | ||
sudo /bin/chown root:disk /dev/loop$i | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
sudo docker inspect --format '{{ .State.Pid }}' "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
scriptdir=`dirname "$BASH_SOURCE"` | ||
sudo nsenter --target $($scriptdir/docker-pid $1) --mount --uts --ipc --net --pid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
scriptdir=`dirname "$BASH_SOURCE"` | ||
echo $scriptdir | ||
|
||
# Create a linux bridge between containers | ||
brctl addbr br-em1 | ||
ip link set br-em1 up | ||
|
||
num_nodes=1 | ||
if [ -z "$CONTIV_NODES" ]; | ||
then | ||
num_nodes=1 | ||
else | ||
num_nodes=$CONTIV_NODES | ||
fi | ||
echo $num_nodes | ||
|
||
netplugin_path=$(pwd) | ||
|
||
cluster="" | ||
first="true" | ||
for i in `seq 1 $num_nodes`; | ||
do | ||
hostname="netplugin-node$i" | ||
echo "Starting $hostname" | ||
sudo docker run -d -i -t --name $hostname --privileged -v /var/lib/docker -v $netplugin_path:/netplugin sachja/ubuntu_netplugin bash -c "/netplugin/scripts/dockerhost/start-service.sh & bash" | ||
sudo nsenter -t $($scriptdir/docker-pid $hostname) -n hostname $hostname | ||
sudo ip link add $i-int type veth peer name $i-ext | ||
sudo brctl addif br-em1 $i-ext | ||
sudo ip link set netns $($scriptdir/docker-pid $hostname) dev $i-int | ||
sudo nsenter -t $($scriptdir/docker-pid $hostname) -n ip link set dev $i-int name eth2 | ||
sudo nsenter -t $($scriptdir/docker-pid $hostname) -n ip link set eth2 up | ||
if [ $i -gt "1" ]; then | ||
cluster=$cluster","; | ||
fi | ||
sudo docker exec $hostname service docker start | ||
addr=$($scriptdir/docker-ip $hostname) | ||
cluster=$cluster$hostname"=http://"$addr":2380" | ||
first="false" | ||
done | ||
|
||
echo $cluster | ||
|
||
for i in `seq 1 $num_nodes`; | ||
do | ||
hostname="netplugin-node$i" | ||
echo "Starting etcd on $hostname" | ||
addr=$($scriptdir/docker-ip $hostname) | ||
sudo docker exec $hostname etcd -name $hostname -data-dir /opt/etcd -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -advertise-client-urls http://$addr:2379,http://$addr:4001 -initial-advertise-peer-urls http://$addr:2380 -listen-peer-urls http://$addr:2380 -initial-cluster $cluster -initial-cluster-state new & | ||
done | ||
|
||
for i in `seq 1 $num_nodes`; | ||
do | ||
hostname="netplugin-node$i" | ||
echo "Starting netplugin on $hostname" | ||
sudo docker exec $hostname /netplugin/bin/netplugin -host-label host$i & | ||
done | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
/etc/init.d/openvswitch-switch restart | ||
while true | ||
do | ||
echo service is running >> service.log | ||
sleep 10 | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sachja overall LGTM
Suggest replacing
If you cannot...
withIf you cannot launch a VM on your host, especially when the host is a VM itself, you can also...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done