手把手二进制安装K8S教程:第六章《Node部署flannel网络》

请先阅读《手把手二进制安装K8S教程:第五章《部署master节点》》
192.168.75.131 Node 进行
192.168.75.132 Node 进行


下载flannel安装包

wget https://github.com/coreos/flannel/releases/download/v0.9.1/flannel-v0.9.1-linux-amd64.tar.gz
tar zxf flannel-v0.9.1-linux-amd64.tar.gz
mkdir  /app/kubernetes/bin/
mv flanneld mk-docker-opts.sh /app/kubernetes/bin/
cat < /etc/sysconfig/flanneld
FLANNEL_OPTIONS="--etcd-endpoints=https://192.168.75.130:2379,https://192.168.75.131:2379,https://192.168.75.132:2379 \
-etcd-cafile=/app/kubernetes/ssl/ca.pem \
-etcd-certfile=/app/kubernetes/ssl/kubernetes.pem \
-etcd-keyfile=/app/kubernetes/ssl/kubernetes-key.pem"
EOF
cat </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=/etc/sysconfig/flanneld
ExecStart=/app/kubernetes/bin/flanneld --ip-masq \$FLANNEL_OPTIONS
ExecStartPost=/app/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
Restart=on-failure

[Install]
WantedBy=multi-user.target

EOF

设置docker启动文件

cat </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 --insecure-registry http://lcb.docker.com:5000
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

写入分配的子网段到etcd,供flanneld使用,注意替换IP

etcdctl --ca-file=/app/kubernetes/ssl/ca.pem --cert-file=/app/kubernetes/ssl/kubernetes.pem --key-file=/app/kubernetes/ssl/kubernetes-key.pem --endpoints="https://192.168.75.130:2379,https://192.168.75.131:2379,https://192.168.75.132:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
etcdctl --ca-file=/app/kubernetes/ssl/ca.pem --cert-file=/app/kubernetes/ssl/kubernetes.pem --key-file=/app/kubernetes/ssl/kubernetes-key.pem --endpoints="https://192.168.75.130:2379,https://192.168.75.131:2379,https://192.168.75.132:2379" get /coreos.com/network/config

启动flannel

systemctl daemon-reload
systemctl start flanneld.service
systemctl enable flanneld.service

重启docker

systemctl daemon-reload
systemctl restart docker

可以看到docker的虚拟网桥的ip已经应用到flannel网络中
手把手二进制安装K8S教程:第六章《Node部署flannel网络》_第1张图片

测试
node01上docker网桥的ip为:172.17.31.1,node02上docker网桥ip为:172.17.33.1。
测试flannel是否正常工作的最简单的方法就是在一个node节点上ping另一个node节点的docker网桥,能通则工作正常。

查看etcd存储的flannel网络信息
查看flannel分配的网段和网络类型

etcdctl --ca-file=/app/kubernetes/ssl/ca.pem --cert-file=/app/kubernetes/ssl/kubernetes.pem --key-file=/app/kubernetes/ssl/kubernetes-key.pem --endpoints="https://192.168.75.130:2379,https://192.168.75.131:2379,https://192.168.75.132:2379" get /coreos.com/network/config

2019-04-23 18:48:26.391528 I | warning: ignoring ServerName for user-provided CA for backwards compatibility is deprecated
{ “Network”: “172.17.0.0/16”, “Backend”: {“Type”: “vxlan”}}

查看subnets中保存的key

etcdctl --ca-file=/app/kubernetes/ssl/ca.pem --cert-file=/app/kubernetes/ssl/kubernetes.pem --key-file=/app/kubernetes/ssl/kubernetes-key.pem --endpoints="https://192.168.75.130:2379,https://192.168.75.131:2379,https://192.168.75.132:2379" ls /coreos.com/network/subnets

2019-04-23 18:49:21.007922 I | warning: ignoring ServerName for user-provided CA for backwards compatibility is deprecated
/coreos.com/network/subnets/172.17.31.0-24
/coreos.com/network/subnets/172.17.33.0-24

以上内容参考
https://jimmysong.io/kubernetes-handbook/practice/flannel-installation.html

作者留言:本人也是刚开始接触K8S,如果网友通过本人的教程如果有什么问题欢迎留言,一起排错,互相学习,共同进步!

你可能感兴趣的:(手把手二进制安装K8S教程)