[root@k8s-master src]# wget https://github.com/coreos/flannel/releases/download/v0.9.1/flannel-v0.9.1-linux-amd64.tar.gz
[root@k8s-master src]# tar xf flannel-v0.9.1-linux-amd64.tar.gz
[root@k8s-master src]# scp flanneld mk-docker-opts.sh k8s-node01:/opt/kubernetes/bin/
flanneld 100% 33MB 134.8MB/s 00:00
mk-docker-opts.sh 100% 2139 3.9MB/s 00:00
[root@k8s-master src]# scp flanneld mk-docker-opts.sh k8s-node02:/opt/kubernetes/bin/
flanneld 100% 33MB 140.6MB/s 00:00
mk-docker-opts.sh 100% 2139 76.1KB/s 00:00
############
配置Flannel之前,先用etcd给Flannel分配网段
[root@k8s-master ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.56.243:2379,https://192.168.56.244:2379,https://192.168.56.245:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}' { "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}} [root@k8s-master ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.56.243:2379,https://192.168.56.244:2379,https://192.168.56.245:2379" get /coreos.com/network/config { "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}
[root@k8s-master ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.56.243:2379,https://192.168.56.244:2379,https://192.168.56.245:2379" ls /coreos.com/network/subnets /coreos.com/network/subnets/172.17.7.0-24 /coreos.com/network/subnets/172.17.9.0-24
[root@k8s-master ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.56.243:2379,https://192.168.56.244:2379,https://192.168.56.245:2379" get /coreos.com/network/subnets/172.17.7.0-24 {"PublicIP":"192.168.56.245","BackendType":"vxlan","BackendData":{"VtepMAC":"d2:ba:51:66:61:9f"}} [root@k8s-master ssl]# /opt/kubernetes/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.56.243:2379,https://192.168.56.244:2379,https://192.168.56.245:2379" get /coreos.com/network/subnets/172.17.9.0-24 {"PublicIP":"192.168.56.244","BackendType":"vxlan","BackendData":{"VtepMAC":"d2:cd:86:e7:54:7c"}}
##############flannel配置脚本
#!/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/kubernetes/ssl/ca.pem -etcd-certfile=/opt/kubernetes/ssl/server.pem -etcd-keyfile=/opt/kubernetes/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-master src]# scp flannel.sh k8s-node01:/usr/local/src/
flannel.sh 100% 1461 2.8MB/s 00:00
[root@k8s-master src]# scp flannel.sh k8s-node02:/usr/local/src/
[root@k8s-node01 ssl]# cd /usr/local/src/ [root@k8s-node01 src]# ll total 4 -rw-r--r-- 1 root root 1461 May 28 05:45 flannel.sh [root@k8s-node01 src]# sh flannel.sh Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service. [root@k8s-node01 src]# systemctl start flanneld [root@k8s-node01 src]# ip add 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:50:56:98:8f:f2 brd ff:ff:ff:ff:ff:ff inet 192.168.56.244/24 brd 192.168.56.255 scope global noprefixroute ens192 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe98:8ff2/64 scope link valid_lft forever preferred_lft forever 3: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default link/ether d2:cd:86:e7:54:7c brd ff:ff:ff:ff:ff:ff inet 172.17.9.0/32 scope global flannel.1 valid_lft forever preferred_lft forever inet6 fe80::d0cd:86ff:fee7:547c/64 scope link valid_lft forever preferred_lft forever 4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:8f:ae:d2:33 brd ff:ff:ff:ff:ff:ff inet 172.17.9.1/24 brd 172.17.9.255 scope global docker0 valid_lft forever preferred_lft forever
[root@k8s-node02 cfg]# cd /usr/local/src/ [root@k8s-node02 src]# sh flannel.sh Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service. [root@k8s-node02 src]# ip add 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:50:56:98:a5:02 brd ff:ff:ff:ff:ff:ff inet 192.168.56.245/24 brd 192.168.56.255 scope global noprefixroute ens192 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe98:a502/64 scope link valid_lft forever preferred_lft forever 3: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default link/ether d2:ba:51:66:61:9f brd ff:ff:ff:ff:ff:ff inet 172.17.7.0/32 scope global flannel.1 valid_lft forever preferred_lft forever inet6 fe80::d0ba:51ff:fe66:619f/64 scope link valid_lft forever preferred_lft forever 4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:b1:6c:a6:c9 brd ff:ff:ff:ff:ff:ff inet 172.17.7.1/24 brd 172.17.7.255 scope global docker0 valid_lft forever preferred_lft forever