flannel实战

雨燕双飞 提交于 2020-11-24 03:15:37

        docker swarm mode的出现是个里程碑,官方原生的编排调度看起来都成雏形了,但是swarm mode和容器外部系统的对接、网络性能始终不尽人意,swarm mode下各种开源周边不能使用,感觉swarm mode自成一个体系,网络方面上篇调研了calico,本篇调研一下flannel,总体感觉大家都是在向K8S靠拢,docker原生这也是凉凉嘛.....

软件信息

软件 版本
OS Ubuntu 16.04.3 LTS
Docker 18.03.0-ce
Etcd 3.3.9
Flannel 0.10.0

主机信息

ubuntu16.04-1

172.31.68.241 workload-A docker、etcd、flannel
ubuntu16.04-2 172.31.68.242 workload-B docker、flannel
ubuntu16.04-3 172.31.68.243 workload-C docker、flannel

工作目录

    /opt/programs:各种软件的下载均在该目录下

docker安装

    下载

wget 'https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_18.03.0~ce-0~ubuntu_amd64.deb'

    安装

dpkg -i docker-ce_18.03.0~ce-0~ubuntu_amd64.deb

    配置

        /etc/docker/daemon.json    

{
  "registry-mirrors": ["http://aa2fd190.m.daocloud.io"],
  "insecure-registries":["http://172.31.68.241"],
  "dns": ["202.96.209.5","202.96.209.133"],
  "experimental": true
}

    启动

systemctl daemon-reload
systemctl restart docker.service

   启动脚本

        /lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock 
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

    注意:以上步骤在三台机器都需要执行

etcd安装

    下载

wget 'https://github-production-release-asset-2e65be.s3.amazonaws.com/11225014/7c787e4c-8f2b-11e8-8a29-4db755239b18?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180813%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180813T090430Z&X-Amz-Expires=300&X-Amz-Signature=dc354d85304b135c99c4d0b606fa07bd75eaaa2fd46b19d43554d9112a4d83d8&X-Amz-SignedHeaders=host&actor_id=12913767&response-content-disposition=attachment%3B%20filename%3Detcd-v3.3.9-linux-amd64.tar.gz&response-content-type=application%2Foctet-stream'

    安装

tar zxvf etcd-v3.3.9-linux-amd64.tar.gz
mv etcd-v3.3.9-linux-amd64 etcd_3.3.9

    配置启动脚本

        /etc/systemd/system/etcd.service

[Unit]
Description=etcd
Documentation=https://github.com/coreos/etcd

[Service]
Type=notify
Restart=always
RestartSec=5s
LimitNOFILE=40000
TimeoutStartSec=0 

ExecStart=/opt/programs/etcd_3.3.9/etcd --name ubuntu16.04-1 \
   --data-dir /var/lib/etcd \
   --listen-client-urls http://172.31.68.241:2379 \
   --listen-peer-urls http://172.31.68.241:2380 \
   --advertise-client-urls http://172.31.68.241:2379 \
   --initial-advertise-peer-urls http://172.31.68.241:2380

[Install]
WantedBy=multi-user.target

    启动

systemctl daemon-reload
systemctl start etcd.service

    验证

etcdctl --endpoints http://172.31.68.241:2379  cluster-health

    注意:以上操作只需要在ubuntu16.04-1上执行

flannel安装

    下载

wget 'https://github-production-release-asset-2e65be.s3.amazonaws.com/21704134/596e76e2-002c-11e8-9359-36689058e7af?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180815%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180815T052949Z&X-Amz-Expires=300&X-Amz-Signature=5b4fda3ddd09110a2a9d17cd65d1af2adef7a608888fc95a2692623768b2daad&X-Amz-SignedHeaders=host&actor_id=12913767&response-content-disposition=attachment%3B%20filename%3Dflannel-v0.10.0-linux-amd64.tar.gz&response-content-type=application%2Foctet-stream'

    安装

mkdir /opt/programs/flannel_0.10.0
tar zxvf flannel-v0.10.0-linux-amd64.tar.gz -C /opt/programs/flannel_0.10.0

    etcd配置网段

etcdctl --endpoints http://172.31.68.241:2379 set /flannel/network/config '{"Network":"192.168.0.0/16","Backend":{"Type":"vxlan"}}'

    启动flannel

flanneld -etcd-endpoints=http://172.31.68.241:2379 -ip-masq=true -etcd-prefix=/flannel/network

    配置启动脚本

        /lib/systemd/system/flannel.service

[Unit]
Description=coreos flannel
Documentation=https://my.oschina.net/guol/blog/1928408
After=docker.service


[Service]
TimeoutSec=0
ExecStart=/opt/programs/flannel_0.10.0/flanneld -etcd-endpoints=http://172.31.68.241:2379 -ip-masq=true -etcd-prefix=/flannel/network
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 

[Install]
WantedBy=multi-user.target

    生产docker配置

mk-docker-opts.sh

        ps:生成的文件在/run/docker_opts.env

    调整docker参数

        /lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
EnvironmentFile=/run/docker_opts.env
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock $DOCKER_OPTS
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

    重启docker

systemctl daemon-reload
systemctl start docker.service

    查看网卡

    注意:以上部署需要在三台机器上都执行,上例是以ubuntu16.04-1为例进行演示,"etcd配置网段"只需要执行一次即可

Etcd数据验证

etcdctl --endpoints http://172.31.68.241:2379 ls /flannel/network/subnets/

启动测试容器

    分别在三台机器上启动一个容器实例

docker run  --name workload-A -ti 172.31.68.241/library/xenial3
docker run  --name workload-B -ti 172.31.68.241/library/xenial3
docker run  --name workload-C -ti 172.31.68.241/library/xenial3

联通测试

    容器间通讯

        workload-A --> workload-C

    容器宿主机通讯

        workload-C  --> ubuntu16.04-1

    主机容器通讯

        ubuntu16.04-3 --> workload-B

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!