Merge pull request #36 from lowescott/ipvlan-update

Commit new version of Docker+IPVLAN environment
This commit is contained in:
Scott S. Lowe 2016-03-21 23:38:46 -06:00
commit 01dbd95378
5 changed files with 74 additions and 31 deletions

View file

@ -4,52 +4,52 @@ These files were created to allow users to use Vagrant ([http://www.vagrantup.co
## Contents
* **docker-provision.sh**: This shell script configures the Docker host VM with an experimental build of the Docker binary. No changes to this file are necessary.
* **machines.yml**: This is a YAML file containing the configuration data used by Vagrant when creating and provisioning VMs. This particular Vagrant environment requires six (6) values in this file for each VM: `name` (name to be assigned to the box as well as used for hostname), `box` (the name of the Vagrant box), `ram` (desired RAM), `vcpu` (number of virtual CPUs), `ip_addr` (the private IP address to be assigned to the second network interface; also controls whether a second interface is provisioned), and `docker` (set to "true" or "false"; controls whether Vagrant provisions Docker onto the VM).
* **README.md**: The file you're currently reading.
* **remote-provision.sh**: This shell script configures the remote VM used for testing connectivity. No changes to this file are necessary.
* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines for this environment. No changes need to be made to this document, as all the configuration data is found in other files (like `machines.yml`). However, if you are using a virtualization solution _other_ than VMware Fusion, you might need to make changes to this file.
## Instructions
These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. Note that Internet access is required when using `vagrant up` to create this environment.
1. Use `vagrant box add` to install _both_ an Ubuntu 15.04 x86_64 box _and_ an Ubuntu 14.04 x86_64 Vagrant box. I have an Ubuntu 14.04 x86_64 base box you can use; to use my base box, add the box with `vagrant box add slowe/ubuntu-trusty-x64`. A Vagrant box you might consider using for Ubuntu 15.04 is the `bento/ubuntu-15.04` box.
1. Use `vagrant box add` to install a 64-bit Ubuntu 15.10 box. I have an Ubuntu 15.10 base box you can use; to use my base box, add the box with `vagrant box add slowe/ubuntu-15.10-server-amd64`. You'll also want to install a 64-bit Ubuntu 14.04 box; you can use `vagrant box add slowe/ubuntu-trusty-x64` to use my base box.
2. Place the files from the `docker-ipvlan` directory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (using `git clone`) or just download the specific files from the the `docker-ipvlan` folder.
3. If necessary, edit `machines.yml` to specify the name of the Vagrant boxes downloaded in step 1. The VM definition for "docker-01" **must** use Ubuntu 15.04; the other VM may use any version of Ubuntu you prefer. You may also make changes to the private IP addresses or the RAM/CPU settings, although no changes are typically required.
3. If necessary, edit `machines.yml` to specify the name of the Vagrant boxes downloaded in step 1. Editing this file is only necessary if you are _not_ using my base boxes. The VM definition for "docker-01" **must** use Ubuntu 15.10; the other VM may use any version of Ubuntu you prefer. I do not recommend making any other changes to this file.
4. Run `vagrant up` to instantiate the learning environment. This will spin up two (2) VMs based on the Vagrant boxes you downloaded in step 1 and specified in `machines.yml` in step 3. Vagrant will also appropriately configure each VM and start the necessary services. Depending on the speed of your system and your Internet connection, this may take a few minutes.
5. Use `vagrant ssh docker-01` to connect to the first Docker host and run the following commands to download and install the ipvlan plugin for Docker:
5. Use `vagrant ssh docker-01` to connect to the Docker host VM. Run `sudo docker pull alpine:latest` to pull down the latest Alpine image for Docker.
git clone https://github.com/gopher-net/ipvlan-docker-plugin.git
cd ipvlan-docker-plugin/binaries
sudo ./ipvlan-docker-plugin-0.2-Linux-x86_64 \
--ipvlan-subnet "192.168.100.0/24" \
--gateway "192.168.100.1" --mode "l2" \
--host-interface "eth1" -d &
6. While still logged into the Docker host VM, run this command to create a Docker network backed by the IPVLAN driver:
If you changed the private IP addresses in `machines.yml`, be sure to supply the appropriate IP address ranges from that file in the command above.
sudo docker network create -d ipvlan \
--subnet=192.168.100.0/24 --gateway=192.168.100.1 \
-o ipvlan_mode=l2 -o parent=ens33 ipvlan100
6. Run this command to create a network using the ipvlan plugin:
7. Launch a "target" container on the Docker host VM to use in verifying connectivity:
docker network create -d ipvlan --subnet=192.168.100.0/24 \
--gateway=192.168.100.1 -o host_iface=eth1 -o mode=l2 testnet
sudo docker run --net=ipvlan100 --ip=192.168.100.10 -itd alpine /bin/sh
Note that the subnet, gateway, host interface, and mode specified here need to match what was provided when the plugin was launched in step 5.
8. In a separate terminal window, use `vagrant ssh remote-01` to connect to the remote system. Test connectivity to the "target" container with `ping -c 4 192.168.100.10`.
7. Launch a Docker container attached to this new network with this command line:
9. In the terminal window for the Docker host VM, launch another container with this command:
docker run -it --rm --net=testnet ubuntu
sudo docker run --net=ipvlan100 --ip=192.168.100.11 -it --rm alpine /bin/sh
This will drop you at a root prompt for an Ubuntu container. Use `ip addr list` to determine the IP address assigned to this container.
This will drop you at a container root prompt. Test connectivity to the other container:
8. In a separate terminal window, switch to the directory where the files for this environment are stored and connect to the remote VM using `vagrant ssh remote-01`.
ping -c 4 192.168.100.10
9. In the remote VM, ping the IP address of the container (obtained in step 7 when you launched the container).
Now test connectivity to the remote client system:
10. From the container prompt, ping the IP address assigned to the remote VM (by default, 192.168.100.101).
ping -c 4 192.168.100.101
Enjoy!
You've just deployed IPVLAN L2 interfaces with Docker. Enjoy!

View file

@ -36,9 +36,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
srv.vm.synced_folder '.', '/vagrant', disabled: true
end #if machine['sync_disabled']
# Assign additional private network
if machine['ip_addr'] != nil
srv.vm.network 'private_network', ip: machine['ip_addr']
# Assign additional private network per settings in machines.yml
if machine['priv_ip'] == true
srv.vm.network 'private_network', auto_config: false
end # if machine['ip_addr']
# Configure CPU & RAM per settings in machines.yml (Fusion)
@ -56,10 +56,16 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vb.cpus = machine['vcpu']
end # srv.vm.provider virtualbox
# Provision Docker on appropriate VMs
if machine['docker'] == true
srv.vm.provision 'docker'
end # if machine['docker']
# Provision 'docker-01'
if machine['name'] == 'docker-01'
srv.vm.provision 'docker'
srv.vm.provision 'shell', path: 'docker-provision.sh'
end # if machine['name']
# Provision 'remote-01'
if machine['name'] == 'remote-01'
srv.vm.provision 'shell', path: 'remote-provision.sh'
end # if machine['name']
end # config.vm.define
end # machines.each
end # Vagrant.configure

View file

@ -0,0 +1,32 @@
#!/bin/bash
# Provision secondary network interface
sudo ip addr add 192.168.100.100/24 dev ens33
sudo ip link set ens33 up
# Install curl if needed
if [[ ! -e /usr/bin/curl ]]; then
apt-get update
apt-get -yqq install curl
fi
if [[ ! -e /usr/local/bin/docker-latest ]]; then
# Get download of experimental Docker binary
curl -sLO https://experimental.docker.com/builds/Linux/x86_64/docker-latest
# Set properties on Docker binary
chmod a+x docker-latest
# Move etcd and etcdctl to /usr/local/bin
sudo mv docker-latest /usr/local/bin/
# Stop existing Docker daemon
sudo systemctl stop docker
# Substitute experimental Docker binary for existing version
sudo mv /usr/bin/docker /usr/bin/docker-old
sudo ln -s /usr/local/bin/docker-latest /usr/bin/docker
# Restart Docker service
sudo systemctl start docker
fi

View file

@ -1,13 +1,13 @@
---
- name: docker-01
box: bento/ubuntu-15.04
box: slowe/ubuntu-15.10-server-amd64
ram: 1024
vcpu: 1
ip_addr: 192.168.100.100
priv_ip: true
docker: true
- name: remote-01
box: slowe/ubuntu-trusty-x64
ram: 512
vcpu: 1
ip_addr: 192.168.100.101
priv_ip: true
docker: false

View file

@ -0,0 +1,5 @@
#!/bin/bash
# Provision secondary network interface
sudo ip addr add 192.168.100.101/24 dev eth1
sudo ip link set eth1 up