k8s二进制部署(二)
安装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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
##查看网络模式
/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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" get /coreos.com/network/config
在三台主机上相同配置,可使用scp传输:
##创建目录
mkdir /opt/kubernetes_flannel/{cfg,ssl,bin} -p
##解压文件
tar -zxvf flannel-v0.11.0-linux-amd64.tar.gz
mv flanneld mk-docker-opts.sh /opt/kubernetes_flannel/bin/
##配置证书
cp /opt/k8s/etcd-cert/{ca.pem,server.pem,server-key.pem} /opt/kubernetes_flannel/ssl/
##创建config配置文件
cat > /opt/kubernetes_flannel/cfg/flanneld.conf << EOF FLANNEL_ETCD="-etcd-endpoints=https://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" FLANNEL_ETCD_KEY="-etcd-prefix=/coreos.com/network" FLANNEL_ETCD_CAFILE="--etcd-cafile=/opt/kubernetes_flannel/ssl/ca.pem" FLANNEL_ETCD_CERTFILE="--etcd-certfile=/opt/kubernetes_flannel/ssl/server.pem" FLANNEL_ETCD_KEYFILE="--etcd-keyfile=/opt/kubernetes_flannel/ssl/server-key.pem" EOF
##创建flannel的service文件
cat > /usr/lib/systemd/system/flanneld.service << EOF [Unit] Description=Flanneld overlay address etcd agent After=network.target Before=docker.service [Service] Type=notify EnvironmentFile=-/opt/kubernetes_flannel/cfg/flanneld.conf ExecStart=/opt/kubernetes_flannel/bin/flanneld ${FLANNEL_ETCD} ${FLANNEL_ETCD_KEY} ${FLANNEL_ETCD_CAFILE} ${FLANNEL_ETCD_CERTFILE} ${FLANNEL_ETCD_KEYFILE} ExecStartPost=/opt/kubernetes_flannel/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env Restart=on-failure [Install] WantedBy=multi-user.target RequiredBy=docker.service EOF
##修改docker的service文件使其使用flannel网络
cat > /usr/lib/systemd/system/docker.service << EOF [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
##启动flannel
systemctl daemon-reload
systemctl start flanneld
##重新启动docker
systemctl restart docker
##查看flannel,docker的启动和etcd里存储的信息
ps -ef | grep flanneld
ps -ef | grep docker
/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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" ls /coreos.com/network/subnets/
/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://10.107.141.50:2379,https://10.107.141.51:2379,https://10.107.141.52:2379" get /coreos.com/network/subnets/ip
- 点赞
- 收藏
- 关注作者
评论(0)