Kubernetes集群开启IPVS负载均衡

嚯嚯嚯www 28 2022-08-26

Kubernetes集群开启IPVS负载均衡

理论参考:https://www.cnblogs.com/hongdada/p/9758939.html
步骤参考:https://www.jianshu.com/p/9b4b700c7765

环境:已安装完成Kubernetes+Dashborad
master节点192.168.1.10/centos7
node节点 192.168.1.11/centos7

配置IPVS

[root@master ~]# touch /etc/sysconfig/modules/ipvs.modules
[root@master ~]# vim /etc/sysconfig/modules/ipvs.modules
#写入以下内容
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4

[root@master ~]# chmod 755 /etc/sysconfig/modules/ipvs.modules
[root@master ~]# bash /etc/sysconfig/modules/ipvs.modules
#验证
[root@master ~]# lsmod|grep -e ip_vs -e nf_conntrack_ipv4
nf_conntrack_ipv4      15053  0 
nf_defrag_ipv4         12729  1 nf_conntrack_ipv4
ip_vs_sh               12688  0 
ip_vs_wrr              12697  0 
ip_vs_rr               12600  0 
ip_vs                 145497  6 ip_vs_rr,ip_vs_sh,ip_vs_wrr
nf_conntrack          139224  2 ip_vs,nf_conntrack_ipv4
libcrc32c              12644  3 xfs,ip_vs,nf_conntrack
[root@master ~]# yum -y install ipset ipvsadm

node节点相同操作

开启IPVS

修改ConfigMap的kube-system/kube-proxy中的config.conf文件,修改为 mode: “ipvs”

[root@master .kube]# kubectl edit cm kube-proxy -n kube-system
configmap/kube-proxy edited
#进入后编辑方法同vim

53347-tktrlnjqugp.png

重启kube-proxy

此处执行删除会自动创建

[root@master .kube]# kubectl get pod -n kube-system | grep kube-proxy
kube-proxy-8ndgz                        1/1     Running   0          92m
kube-proxy-lxdbj                        1/1     Running   0          96m
[root@master .kube]# kubectl delete pod kube-proxy-8ndgz -n kube-system
pod "kube-proxy-8ndgz" deleted
[root@master .kube]# kubectl delete pod kube-proxy-lxdbj -n kube-system
pod "kube-proxy-lxdbj" deleted
或者执行
[root@master .kube]# kubectl get pod -n kube-system | grep kube-proxy | awk '{system("kubectl delete pod "$1" -n kube-system")}' 
pod "kube-proxy-hh2b5" deleted
pod "kube-proxy-mzp54" deleted

测试IPVS

使用命令ipvsadm –Ln查看创建的服务是否使用ipvs创建集群
23302-7t1hlm7ppp7.png

查询kube-proxy日志
如图已经显示使用ipvs
51578-9ql7zklicgq.png

K8S节点调度,污点(taint)

参考:https://blog.frognew.com/2018/05/taint-and-toleration.html

默认配置下Kubernetes不会将Pod调度Master节点

#kubectl describe node master查看master节点Taints字段配置
[root@master modules]# kubectl describe node master|grep Taints
Taints:             node-role.kubernetes.io/master:NoSchedule
#执行以下命令将master做node使用
[root@master modules]# kubectl taint node master node-role.kubernetes.io/master-
#再次查询字段以改变
[root@master modules]# kubectl describe node master|grep Taints

Taints: