]> git.proxmox.com Git - mirror_ovs.git/blame - INSTALL.Docker.md
datapath: Update the CT state key only after nf_conntrack_in().
[mirror_ovs.git] / INSTALL.Docker.md
CommitLineData
542cc9bb
TG
1How to Use Open vSwitch with Docker
2====================================
ec8f0f0c 3
eaa923e3 4This document describes how to use Open vSwitch with Docker 1.9.0 or
4384556d
GS
5later. This document assumes that you installed Open vSwitch by following
6[INSTALL.md] or by using the distribution packages such as .deb or .rpm.
7Consult www.docker.com for instructions on how to install Docker.
ec8f0f0c 8
eaa923e3
GS
9Docker 1.9.0 comes with support for multi-host networking. Integration
10of Docker networking and Open vSwitch can be achieved via Open vSwitch
11virtual network (OVN).
12
ec8f0f0c
GS
13
14Setup
eaa923e3
GS
15=====
16
17For multi-host networking with OVN and Docker, Docker has to be started
18with a destributed key-value store. For e.g., if you decide to use consul
19as your distributed key-value store, and your host IP address is $HOST_IP,
20start your Docker daemon with:
21
22```
23docker daemon --cluster-store=consul://127.0.0.1:8500 \
24--cluster-advertise=$HOST_IP:0
25```
26
27OVN provides network virtualization to containers. OVN's integration with
28Docker currently works in two modes - the "underlay" mode or the "overlay"
29mode.
30
31In the "underlay" mode, OVN requires a OpenStack setup to provide container
32networking. In this mode, one can create logical networks and can have
33containers running inside VMs, standalone VMs (without having any containers
34running inside them) and physical machines connected to the same logical
35network. This is a multi-tenant, multi-host solution.
36
37In the "overlay" mode, OVN can create a logical network amongst containers
38running on multiple hosts. This is a single-tenant (extendable to
39multi-tenants depending on the security characteristics of the workloads),
40multi-host solution. In this mode, you do not need a pre-created OpenStack
41setup.
42
43For both the modes to work, a user has to install and start Open vSwitch in
44each VM/host that he plans to run his containers.
45
46
47The "overlay" mode
48==================
49
50OVN in "overlay" mode needs a minimum Open vSwitch version of 2.5.
51
52* Start the central components.
53
54OVN architecture has a central component which stores your networking intent
55in a database. On one of your machines, with an IP Address of $CENTRAL_IP,
56where you have installed and started Open vSwitch, you will need to start some
57central components.
58
eaa923e3
GS
59Start ovn-northd daemon. This daemon translates networking intent from Docker
60stored in the OVN_Northbound database to logical flows in OVN_Southbound
61database.
62
63```
64/usr/share/openvswitch/scripts/ovn-ctl start_northd
65```
66
67* One time setup.
68
69On each host, where you plan to spawn your containers, you will need to
70run the following command once. (You need to run it again if your OVS database
71gets cleared. It is harmless to run it again in any case.)
72
73$LOCAL_IP in the below command is the IP address via which other hosts
74can reach this host. This acts as your local tunnel endpoint.
75
76$ENCAP_TYPE is the type of tunnel that you would like to use for overlay
77networking. The options are "geneve" or "stt". (Please note that your
78kernel should have support for your chosen $ENCAP_TYPE. Both geneve
79and stt are part of the Open vSwitch kernel module that is compiled from this
80repo. If you use the Open vSwitch kernel module from upstream Linux,
81you will need a minumum kernel version of 3.18 for geneve. There is no stt
82support in upstream Linux. You can verify whether you have the support in your
83kernel by doing a "lsmod | grep $ENCAP_TYPE".)
84
85```
d61fbedc
GS
86ovs-vsctl set Open_vSwitch . external_ids:ovn-remote="tcp:$CENTRAL_IP:6642" \
87 external_ids:ovn-nb="tcp:$CENTRAL_IP:6641" external_ids:ovn-encap-ip=$LOCAL_IP external_ids:ovn-encap-type="$ENCAP_TYPE"
eaa923e3
GS
88```
89
90And finally, start the ovn-controller. (You need to run the below command
91on every boot)
92
93```
94/usr/share/openvswitch/scripts/ovn-ctl start_controller
95```
96
97* Start the Open vSwitch network driver.
98
99By default Docker uses Linux bridge for networking. But it has support
100for external drivers. To use Open vSwitch instead of the Linux bridge,
101you will need to start the Open vSwitch driver.
102
103The Open vSwitch driver uses the Python's flask module to listen to
104Docker's networking api calls. So, if your host does not have Python's
105flask module, install it with:
106
107```
108easy_install -U pip
109pip install Flask
110```
111
112Start the Open vSwitch driver on every host where you plan to create your
113containers.
114
115```
116ovn-docker-overlay-driver --detach
117```
118
119Docker has inbuilt primitives that closely match OVN's logical switches
120and logical port concepts. Please consult Docker's documentation for
121all the possible commands. Here are some examples.
122
123* Create your logical switch.
124
125To create a logical switch with name 'foo', on subnet '192.168.1.0/24' run:
126
127```
128NID=`docker network create -d openvswitch --subnet=192.168.1.0/24 foo`
129```
130
131* List your logical switches.
132
133```
134docker network ls
135```
136
137You can also look at this logical switch in OVN's northbound database by
138running the following command.
139
140```
ea46a4e9 141ovn-nbctl --db=tcp:$CENTRAL_IP:6640 ls-list
eaa923e3
GS
142```
143
144* Docker creates your logical port and attaches it to the logical network
145in a single step.
146
147For e.g., to attach a logical port to network 'foo' inside cotainer busybox,
148run:
149
150```
151docker run -itd --net=foo --name=busybox busybox
152```
153
154* List all your logical ports.
155
156Docker currently does not have a CLI command to list all your logical ports.
157But you can look at them in the OVN database, by running:
ec8f0f0c 158
542cc9bb 159```
31ed1192 160ovn-nbctl --db=tcp:$CENTRAL_IP:6640 lsp-list $NID
542cc9bb 161```
ec8f0f0c 162
eaa923e3 163* You can also create a logical port and attach it to a running container.
ec8f0f0c 164
542cc9bb 165```
eaa923e3
GS
166docker network create -d openvswitch --subnet=192.168.2.0/24 bar
167docker network connect bar busybox
542cc9bb 168```
ec8f0f0c 169
eaa923e3
GS
170You can delete your logical port and detach it from a running container by
171running:
172
173```
174docker network disconnect bar busybox
175```
ec8f0f0c 176
eaa923e3 177* You can delete your logical switch by running:
ec8f0f0c 178
eaa923e3
GS
179```
180docker network rm bar
181```
ec8f0f0c 182
ec8f0f0c 183
eaa923e3
GS
184The "underlay" mode
185===================
186
187This mode requires that you have a OpenStack setup pre-installed with OVN
188providing the underlay networking.
189
190* One time setup.
191
192A OpenStack tenant creates a VM with a single network interface (or multiple)
193that belongs to management logical networks. The tenant needs to fetch the
194port-id associated with the interface via which he plans to send the container
195traffic inside the spawned VM. This can be obtained by running the
196below command to fetch the 'id' associated with the VM.
ec8f0f0c 197
05444f07 198```
eaa923e3 199nova list
05444f07 200```
ec8f0f0c 201
eaa923e3 202and then by running:
ec8f0f0c 203
eaa923e3
GS
204```
205neutron port-list --device_id=$id
206```
ec8f0f0c 207
eaa923e3
GS
208Inside the VM, download the OpenStack RC file that contains the tenant
209information (henceforth referred to as 'openrc.sh'). Edit the file and add the
210previously obtained port-id information to the file by appending the following
211line: export OS_VIF_ID=$port_id. After this edit, the file will look something
212like:
ec8f0f0c 213
eaa923e3
GS
214```
215#!/bin/bash
216export OS_AUTH_URL=http://10.33.75.122:5000/v2.0
217export OS_TENANT_ID=fab106b215d943c3bad519492278443d
218export OS_TENANT_NAME="demo"
219export OS_USERNAME="demo"
220export OS_VIF_ID=e798c371-85f4-4f2d-ad65-d09dd1d3c1c9
221```
222
223* Create the Open vSwitch bridge.
224
225If your VM has one ethernet interface (e.g.: 'eth0'), you will need to add
226that device as a port to an Open vSwitch bridge 'breth0' and move its IP
227address and route related information to that bridge. (If it has multiple
228network interfaces, you will need to create and attach an Open vSwitch bridge
229for the interface via which you plan to send your container traffic.)
230
231If you use DHCP to obtain an IP address, then you should kill the DHCP client
232that was listening on the physical Ethernet interface (e.g. eth0) and start
233one listening on the Open vSwitch bridge (e.g. breth0).
ec8f0f0c 234
eaa923e3
GS
235Depending on your VM, you can make the above step persistent across reboots.
236For e.g.:, if your VM is Debian/Ubuntu, you can read
237[openvswitch-switch.README.Debian]. If your VM is RHEL based, you can read
238[README.RHEL]
ec8f0f0c 239
ec8f0f0c 240
eaa923e3 241* Start the Open vSwitch network driver.
7894385a 242
eaa923e3
GS
243The Open vSwitch driver uses the Python's flask module to listen to
244Docker's networking api calls. The driver also uses OpenStack's
245python-neutronclient libraries. So, if your host does not have Python's
246flask module or python-neutronclient install them with:
247
248```
249easy_install -U pip
250pip install python-neutronclient
251pip install Flask
7894385a 252```
eaa923e3
GS
253
254Source the openrc file. e.g.:
255````
256. ./openrc.sh
7894385a
GS
257```
258
eaa923e3
GS
259Start the network driver and provide your OpenStack tenant password
260when prompted.
ec8f0f0c 261
eaa923e3
GS
262```
263ovn-docker-underlay-driver --bridge breth0 --detach
264```
ec8f0f0c 265
eaa923e3
GS
266From here-on you can use the same Docker commands as described in the
267section 'The "overlay" mode'.
ec8f0f0c 268
eaa923e3
GS
269Please read 'man ovn-architecture' to understand OVN's architecture in
270detail.
9feb1017 271
eaa923e3
GS
272[INSTALL.md]: INSTALL.md
273[openvswitch-switch.README.Debian]: debian/openvswitch-switch.README.Debian
274[README.RHEL]: rhel/README.RHEL