【原】二进制部署 k8s 1.18.3 (9)

将包拷贝至所有主机对应位置

[root@centos7-nginx flannel]# ansible k8s -m copy -a "src=./flanneld dest=http://www.likecs.com/opt/kubernetes/bin mode=755" [root@centos7-nginx flannel]# ansible k8s -m copy -a "src=./mk-docker-opts.sh dest=http://www.likecs.com/opt/kubernetes/bin mode=755" [root@centos7-nginx flannel]# ansible k8s -m copy -a "src=./remove-docker0.sh dest=http://www.likecs.com/opt/kubernetes/bin mode=755"

准备启动脚本

[root@centos7-nginx scripts]# vim install-flannel.sh [root@centos7-nginx scripts]# bash install-flannel.sh [root@centos7-nginx scripts]# ansible k8s -m script -a "./install-flannel.sh https://10.10.10.128:2379,https://10.10.10.129:2379,https://10.10.10.130:2379"

脚本内容如下:

#!/bin/bash ETCD_ENDPOINTS=${1:-'https://127.0.0.1:2379'} cat >/opt/kubernetes/cfg/flanneld <<EOF FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} \ -etcd-cafile=http://www.likecs.com/opt/kubernetes/ssl/ca.pem \ -etcd-certfile=http://www.likecs.com/opt/kubernetes/ssl/server.pem \ -etcd-keyfile=http://www.likecs.com/opt/kubernetes/ssl/server-key.pem" EOF cat >/usr/lib/systemd/system/flanneld.service <<EOF [Unit] Description=Flanneld Overlay address etcd agent After=network-online.target network.target Before=docker.service [Service] Type=notify EnvironmentFile=http://www.likecs.com/opt/kubernetes/cfg/flanneld #ExecStartPre=http://www.likecs.com/opt/kubernetes/bin/remove-docker0.sh ExecStart=http://www.likecs.com/opt/kubernetes/bin/flanneld --ip-masq \$FLANNEL_OPTIONS #ExecStartPost=http://www.likecs.com/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 systemctl daemon-reload systemctl enable flanneld systemctl restart flanneld

将 pod 网段信息写入 etcd 中

登陆到任意一台 master 节点上

[root@centos7-a ~]# cd k8s-scripts/ [root@centos7-a k8s-scripts]# vim install-flannel-to-etcd.sh [root@centos7-a k8s-scripts]# bash install-flannel-to-etcd.sh https://10.10.10.128:2379,https://10.10.10.129:2379,https://10.10.10.130:2379 10.244.0.0/16 vxlan

脚本内容如下

#!/bin/bash # bash install-flannel-to-etcd.sh https://10.10.10.128:2379,https://10.10.10.129:2379,https://10.10.10.130:2379 10.244.0.0/16 vxlan ETCD_ENDPOINTS=${1:-'https://127.0.0.1:2379'} NETWORK=${2:-'10.244.0.0/16'} NETWORK_MODE=${3:-'vxlan'} ETCDCTL_API=2 etcdctl --ca-file=http://www.likecs.com/opt/etcd/ssl/ca.pem --cert-file=http://www.likecs.com/opt/etcd/ssl/server.pem --key-file=http://www.likecs.com/opt/etcd/ssl/server-key.pem --endpoints=${ETCD_ENDPOINTS} set /coreos.com/network/config '{"Network": '\"$NETWORK\"', "Backend": {"Type": '\"${NETWORK_MODE}\"'}}' #ETCDCTL_API=3 etcdctl --cacert=http://www.likecs.com/opt/etcd/ssl/ca.pem --cert=http://www.likecs.com/opt/etcd/ssl/server.pem --key=http://www.likecs.com/opt/etcd/ssl/server-key.pem --endpoints=${ETCD_ENDPOINTS} put /coreos.com/network/config -- '{"Network": "10.244.0.0/16", "Backend": {"Type": "vxlan"}}'

由于flannel 使用的是v2版本的 etcd,所以此处 etcdctl 使用 v2 的 API

3.12.2 安装 cni-plugin

下载 cni 插件

[root@centos7-nginx ~]# mkdir cni [root@centos7-nginx ~]# cd cni [root@centos7-nginx cni]# wget https://github.com/containernetworking/plugins/releases/download/v0.8.6/cni-plugins-linux-amd64-v0.8.6.tgz [root@centos7-nginx cni]# tar xf cni-plugins-linux-amd64-v0.8.6.tgz [root@centos7-nginx cni]# ll 总用量 106512 -rwxr-xr-x. 1 root root 4159518 5月 14 03:50 bandwidth -rwxr-xr-x. 1 root root 4671647 5月 14 03:50 bridge -rw-r--r--. 1 root root 36878412 6月 17 20:07 cni-plugins-linux-amd64-v0.8.6.tgz -rwxr-xr-x. 1 root root 12124326 5月 14 03:50 dhcp -rwxr-xr-x. 1 root root 5945760 5月 14 03:50 firewall -rwxr-xr-x. 1 root root 3069556 5月 14 03:50 flannel -rwxr-xr-x. 1 root root 4174394 5月 14 03:50 host-device -rwxr-xr-x. 1 root root 3614480 5月 14 03:50 host-local -rwxr-xr-x. 1 root root 4314598 5月 14 03:50 ipvlan -rwxr-xr-x. 1 root root 3209463 5月 14 03:50 loopback -rwxr-xr-x. 1 root root 4389622 5月 14 03:50 macvlan -rwxr-xr-x. 1 root root 3939867 5月 14 03:50 portmap -rwxr-xr-x. 1 root root 4590277 5月 14 03:50 ptp -rwxr-xr-x. 1 root root 3392826 5月 14 03:50 sbr -rwxr-xr-x. 1 root root 2885430 5月 14 03:50 static -rwxr-xr-x. 1 root root 3356587 5月 14 03:50 tuning -rwxr-xr-x. 1 root root 4314446 5月 14 03:50 vlan [root@centos7-nginx cni]# cd .. [root@centos7-nginx ~]# ansible k8s -m copy -a "src=./cni/ dest=http://www.likecs.com/opt/cni/bin mode=755"

创建 cni 配置文件

[root@centos7-nginx scripts]# vim install-cni.sh [root@centos7-nginx scripts]# ansible k8s -m script -a "./install-cni.sh"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzyxyd.html