013.Kubernetes二进制部署worker节点Nginx实现高可用
一 Nginx代理实现kube-apiserver高可用1.1 Nginx实现高可用
基于 nginx 代理的 kube-apiserver 高可用方案。控制节点的 kube-controller-manager、kube-scheduler 是多实例部署,所以只要有一个实例正常,就可以保证高可用;集群内的 Pod 使用 K8S 服务域名 kubernetes 访问 kube-apiserver, kube-dns 会自动解析出多个 kube-apiserver 节点的 IP,所以也是高可用的;在每个节点起一个 nginx 进程,后端对接多个 apiserver 实例,nginx 对它们做健康检查和负载均衡;kubelet、kube-proxy、controller-manager、scheduler 通过本地的 nginx(监听 127.0.0.1)访问 kube-apiserver,从而实现 kube-apiserver 的高可用;从而基于 nginx 4 层透明代理功能实现 K8S 节点( master 节点和 worker 节点)高可用访问 kube-apiserver 。1.2 下载编译Nginx
提示:k8smaster01节点已下载相应二进制,可直接分发至node节点。解释:--with-stream:开启 4 层透明转发(TCP Proxy)功能;--without-xxx:关闭所有其他功能,这样生成的动态链接二进制程序依赖最小。1.3 安装和部署Nginx
1 [root@k8smaster01 ~]# cd /opt/k8s/work 2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 mkdir -p /opt/k8s/kube-nginx/{conf,logs,sbin}
7 done #创建Nginx目录
8 [root@k8smaster01 ~]# cd /opt/k8s/work
9 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
10 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
11do
12 echo ">>> ${node_ip}"
13 scp /opt/k8s/work/nginx-1.15.3/nginx-prefix/sbin/nginx root@${node_ip}:/opt/k8s/kube-nginx/sbin/kube-nginx
14 ssh root@${node_ip} "chmod a+x /opt/k8s/kube-nginx/sbin/*"
15 ssh root@${node_ip} "mkdir -p /opt/k8s/kube-nginx/{conf,logs,sbin}"
16 done #分发Nginx二进制
1.4 配置Nginx 四层透明转发
1 [root@k8smaster01 ~]# cd /opt/k8s/work
提示:k8smaster01节点已配置Nginx 四层透明转发,可直接分发至node节点。 1 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh 2 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
3do
4 echo ">>> ${node_ip}"
5 scp kube-nginx.conf root@${node_ip}:/opt/k8s/kube-nginx/conf/kube-nginx.conf
6 done #分发Nginx四层透明代理配置文件
1.5 配置Nginx system
提示:k8smaster01节点已配置Nginx system,可直接分发至node节点。1.6 分发Nginx systemd
1 [root@k8smaster01 ~]# cd /opt/k8s/work 2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 scp kube-nginx.service root@${node_ip}:/etc/systemd/system/
7 done
二 启动并验证2.1 启动Nginx
1 [root@k8smaster01 ~]# cd /opt/k8s/work 2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 ssh root@${node_ip} "systemctl daemon-reload && systemctl enable kube-nginx && systemctl restart kube-nginx"
7 done
2.2 检查Nginx服务
1 [root@k8smaster01 ~]# cd /opt/k8s/work 2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 ssh root@${node_ip} "systemctl status kube-nginx |grep "Active:""
7 done
2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 mkdir -p /opt/k8s/kube-nginx/{conf,logs,sbin}
7 done #创建Nginx目录
8 [root@k8smaster01 ~]# cd /opt/k8s/work
9 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
10 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
11do
12 echo ">>> ${node_ip}"
13 scp /opt/k8s/work/nginx-1.15.3/nginx-prefix/sbin/nginx root@${node_ip}:/opt/k8s/kube-nginx/sbin/kube-nginx
14 ssh root@${node_ip} "chmod a+x /opt/k8s/kube-nginx/sbin/*"
15 ssh root@${node_ip} "mkdir -p /opt/k8s/kube-nginx/{conf,logs,sbin}"
16 done #分发Nginx二进制
2 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
3do
4 echo ">>> ${node_ip}"
5 scp kube-nginx.conf root@${node_ip}:/opt/k8s/kube-nginx/conf/kube-nginx.conf
6 done #分发Nginx四层透明代理配置文件
2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 scp kube-nginx.service root@${node_ip}:/etc/systemd/system/
7 done
2.1 启动Nginx
1 [root@k8smaster01 ~]# cd /opt/k8s/work2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 ssh root@${node_ip} "systemctl daemon-reload && systemctl enable kube-nginx && systemctl restart kube-nginx"
7 done
2.2 检查Nginx服务
1 [root@k8smaster01 ~]# cd /opt/k8s/work2 [root@k8smaster01 work]# source /opt/k8s/bin/environment.sh
3 [root@k8smaster01 work]# for node_ip in ${NODE_IPS[@]}
4do
5 echo ">>> ${node_ip}"
6 ssh root@${node_ip} "systemctl status kube-nginx |grep "Active:""
7 done
以上是 013.Kubernetes二进制部署worker节点Nginx实现高可用 的全部内容, 来源链接: utcz.com/z/510897.html