kube-proxy默认使用iptables模式,通过各个node节点上的iptables规则实现service的负载均衡,service ip本身是不存在的,其利用iptables规则来代理至实际pod,但是随着service数量增大,iptables模式由于线性查找,性能会大福降低。
kube-proxy引入了IPVS模式,IPVS模式与iptables同样基于Netfilter,但是采用的hash表,因此当service数量达到一定规模,hash表的查找效率就会显现出来,从而提高service的服务性能。
- sysctl.conf
1 | net.ipv4.ip_forward=1 |
2 | net.bridge.bridge-nf-call-iptables=1 |
3 | net.bridge.bridge-nf-call-ip6tables=1 |
- 开启/etc/kubernetes/proxy配置下
ipvs的内核模块已经被收入linux内核模块,主流linux发行版都是支持
1 | ### |
2 | # kubernetes proxy config |
3 | |
4 | # default config should be adequate |
5 | |
6 | # Add your own! |
7 | KUBE_PROXY_ARGS="--masquerade-all \ |
8 | --feature-gates=SupportIPVSProxyMode=true \ |
9 | --proxy-mode=ipvs \ |
10 | --ipvs-min-sync-period=5s \ |
11 | --ipvs-sync-period=5s \ |
12 | --ipvs-scheduler=rr \ |
13 | --kubeconfig=/etc/kubernetes/kube-proxy.kubeconfig \ |
14 | --cluster-cidr=172.16.0.0/16" |
- 查看ipvs
1 | yum install -y ipvdadm |
相关内容:
https://jusene.github.io/2017/04/20/lvs/
https://jusene.github.io/2017/04/23/lvs-nat-dr/