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