二,三,二进制部署kubernetes docker,flannld篇

二.docker安装参考https://www.cnblogs.com/caonw/articles/11409287.html

Overlay Network:覆盖网络,在基础网络上叠加的一种虚拟网络技术模式,该网络中的主机通过虚拟链路连接起来。
VXLAN:将源数据包封装到UDP中,并使用基础网络的IP/MAC作为外层报文头进行封装,然后在以太网上传输,到达目的地后由隧道端点解封装并将数据发送给目标地址。
Flannel:是Overlay网络的一种,也是将源数据包封装在另一种网络包里面进行路由转发和通信,目前已经支持UDP、VXLAN、AWS VPC和GCE路由等数据转发方式

 

1.首先通过etcd规划flannel网络

[root@k8s-master ~]# /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem \
> --endpoints="https://192.168.1.119:2379,https://192.168.1.120:2379,https://192.168.1.121:2379" \
> set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}

2.创建kubernetes部署目录

[root@k8s-master soft]# mkdir -p /opt/kubernetes/{bin,cfg,ssl}

3.下载flannld安装包,解压至kubernetes部署目录(下载地址:https://github.com/coreos/flannel/releases)

[root@k8s-node2 flannel]# tar zxvf flannel-v0.10.0-linux-amd64.tar.gz
[root@k8s-node2 flannel]# cp flanneld  mk-docker-opts.sh  /opt/kubernetes/bin/

4.配置Flannel

[root@k8s-node2 flannel]# cat flannel.sh 
#!/bin/bash

ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"}

cat <<EOF >/opt/kubernetes/cfg/flanneld

FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} \
-etcd-cafile=/opt/etcd/ssl/ca.pem \
-etcd-certfile=/opt/etcd/ssl/server.pem \
-etcd-keyfile=/opt/etcd/ssl/server-key.pem"

EOF

cat <<EOF >/usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network-online.target network.target
Before=docker.service

[Service]
Type=notify
EnvironmentFile=/opt/kubernetes/cfg/flanneld
ExecStart=/opt/kubernetes/bin/flanneld --ip-masq \$FLANNEL_OPTIONS
ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
Restart=on-failure

[Install]
WantedBy=multi-user.target

EOF

cat <<EOF >/usr/lib/systemd/system/docker.service

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

[Service]
Type=notify
EnvironmentFile=/run/flannel/subnet.env
ExecStart=/usr/bin/dockerd \$DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP \$MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload
systemctl enable flanneld
systemctl restart flanneld
systemctl restart docker

[root@k8s-node2 flannel]# sh flannel.sh 

5.检查是否生效 

[root@k8s-node2 flannel]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.60.1  netmask 255.255.255.0  broadcast 172.17.60.255
        ether 02:42:52:68:df:fc  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.121  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:feac:92a5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ac:92:a5  txqueuelen 1000  (Ethernet)
        RX packets 736529  bytes 551179803 (525.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 525946  bytes 60920935 (58.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

flannel.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1450
        inet 172.17.60.0  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::2ce3:20ff:fe80:fadf  prefixlen 64  scopeid 0x20<link>
        ether 2e:e3:20:80:fa:df  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 8 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2408  bytes 134559 (131.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2408  bytes 134559 (131.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@k8s-node2 flannel]# /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem  --endpoints="https://192.168.1.119:2379,https://192.168.1.120:2379,https://192.168.1.121:2379"  ls /coreos.com/network/
/coreos.com/network/config
/coreos.com/network/subnets
[root@k8s-node2 flannel]# /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem  --endpoints="https://192.168.1.119:2379,https://192.168.1.120:2379,https://192.168.1.121:2379"  ls /coreos.com/network/subnets
/coreos.com/network/subnets/172.17.87.0-24
/coreos.com/network/subnets/172.17.60.0-24
[root@k8s-node2 flannel]# /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem  --endpoints="https://192.168.1.119:2379,https://192.168.1.120:2379,https://192.168.1.121:2379"  get /coreos.com/network/subnets/172.17.87.0-24
{"PublicIP":"192.168.1.120","BackendType":"vxlan","BackendData":{"VtepMAC":"a2:40:e9:8c:d3:59"}}
[root@k8s-node2 flannel]# 

  

  

  

 

 

posted @ 2019-10-08 17:41  caonw  阅读(258)  评论(0编辑  收藏  举报