在容器环境中容器内部部署ovs

Posted dablyo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在容器环境中容器内部部署ovs相关的知识,希望对你有一定的参考价值。


宿主机ubuntu18.04,编译安装ovs2.11.1,
apt install python build-essiential
configure--with-linux=/lib/modules/(uname -r)/build
make
sudo make install
sudo make modules_install
sudo lsmod |grep openvswitch
export PATH=$PATH:/usr/local/share/openvswitch/scripts
sudo ovs-ctl start

docker pull ubuntu:18.04

sudo docker create -it -v/etc/apt/sources.list:/etc/apt/sources.list --name vswitch -h vswitch --cap-add NET_ADMIN --cap-add SYS_NICE ubuntu:18.04 /bin/bash
sudo docker start vswitch
sudo docker exec -it vswitch /bin/bash

进入容器-这里参考:https://aozsky.com/virtuallize/docker_openvswitch
apt install -y iproute2 net-tools iputils-ping
apt install -y build-essiential fakeroot
apt install -y debhelper autoconf automake automake1.10 libssl-dev graphviz python-all python-qt4 python-zopeinterface python-twisted-conch libtool

tar zxvf openvswitch-2.11.1.tar.gz

DEB_BUILD_OPTIONS=‘parallel=8 nocheck‘ fakeroot debian/rules binary

cd ../
dpkg -i ./libopenvswitch_2.11.1-1_amd64.deb
dpkg -i ./openvswitch-common_2.11.1-1_amd64.deb
dpkg -i ./openvswitch-switch_2.11.1-1_amd64.deb
dpkg -i ./python-openvswitch_2.11.1-1_all.deb
dpkg -i openvswitch-vtep_2.11.1-1_amd64.deb
出现如下错误:
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.

cd ./openvswitch-2.11.1/utilities
./ovs-ctl start

ovs-vsctl show

保存为镜像
sudo docker commit vswitch dablyo/ubuntu1804:ovs-2.11.1
sudo docker save -o ubuntu1804-ovs2.11.1.img dablyo/ubuntu1804:ovs-2.11.1


宿主机@ovs2.11.1
sudo docker create -it --privileged=true --name cpe1 --net=none dablyo/ubuntu1804:ovs-2.11.1 /bin/bash

sudo ovs-vsctl add-br br_inside
sudo ovs-vsctl add-br br_outside
sudo ovs-vsctl add-br br_wan1

~/openvswitch-2.11.1/utilities$ sudo ./ovs-docker add-port br_wan1 eth0 cpe1 --ipaddress=10.0.0.1/24
~/openvswitch-2.11.1/utilities$ sudo ./ovs-docker add-port br_outside eth1 cpe1 --ipaddress=172.1.0.2/24
~/openvswitch-2.11.1/utilities$ sudo ./ovs-docker add-port br_inside eth2 cpe1 --ipaddress=192.168.100.2/24


=================以上2.11.1版本失败===以下2.9.2版本可行====================
宿主机
sudo apt install -y openvswitch-common openvswitch-switch
sudo docker pull rastasheep/ubuntu-sshd:18.04
sudo docker create -it -v/etc/apt/sources.list:/etc/apt/sources.list -v/etc/docker/daemon.json:/etc/docker/daemon.json --name vswitch -h vswitch \
--cap-add NET_ADMIN --cap-add SYS_NICE rastasheep/ubuntu-sshd:18.04

容器内:
cd openvswitch-2.9.2
apt install -y iproute2 net-tools iputils-ping
apt install -y build-essential fakeroot
apt install -y debhelper autoconf automake automake1.10 libssl-dev graphviz python-all python-qt4 python-zopeinterface python-twisted-conch libtool
DEB_BUILD_OPTIONS=‘parallel=8 nocheck‘ fakeroot debian/rules binary
dpkg -i .deb
apt install -y uuid-runtime
uuidd start
cd openvswitch-2.9.2/utilities
./ovs-ctl start

sudo docker commit vswitch dablyo/ubuntu1804:ovs-2.11.1
sudo docker save -o ubuntu1804-ovs2.11.1.img dablyo/ubuntu1804:ovs-2.11.1


宿主机@ovs2.9.2
sudo docker create -it --privileged=true --name cpe1 -h cpe1 --net=none dablyo/ubuntu1804:ovs-2.9.2 /bin/bash

sudo ovs-vsctl add-br br_inside
sudo ovs-vsctl add-br br_outside
sudo ovs-vsctl add-br br_wan1

~/openvswitch-2.11.1/utilities$ sudo ./ovs-docker add-port br_wan1 eth0 cpe1
~/openvswitch-2.11.1/utilities$ sudo ./ovs-docker add-port br_outside eth1 cpe1
~/openvswitch-2.11.1/utilities$ sudo ./ovs-docker add-port br_inside eth2 cpe1

以上是关于在容器环境中容器内部部署ovs的主要内容,如果未能解决你的问题,请参考以下文章

干货 | 博云基于OVS自研容器网络插件在金融企业的落地实践

Prometheus容器监控环境部署

K8S的服务注册发现和负载均衡原理

如何将内部 MobileFirst 混合应用程序部署到专用的 Bluemix 环境?

Docker运行python容器

云原生之使用docker部署centos系统测试环境