From c52eac80bfc339afb8a56fc052da6a5799e19bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=A4=A9=E4=B8=8B?= <1136652526@qq.com> Date: Mon, 3 Apr 2023 07:54:55 +0000 Subject: [PATCH] =?UTF-8?q?add=20k8s=E8=AF=A6=E7=BB=86=E6=95=99=E7=A8=8B-?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=89=88/metallb;ingress-nginx=E9=83=A8?= =?UTF-8?q?=E7=BD=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 梦天下 <1136652526@qq.com> --- ...llb;ingress-nginx\351\203\250\347\275\262" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "k8s\350\257\246\347\273\206\346\225\231\347\250\213-\350\260\203\346\225\264\347\211\210/metallb;ingress-nginx\351\203\250\347\275\262" diff --git "a/k8s\350\257\246\347\273\206\346\225\231\347\250\213-\350\260\203\346\225\264\347\211\210/metallb;ingress-nginx\351\203\250\347\275\262" "b/k8s\350\257\246\347\273\206\346\225\231\347\250\213-\350\260\203\346\225\264\347\211\210/metallb;ingress-nginx\351\203\250\347\275\262" new file mode 100644 index 0000000..165c613 --- /dev/null +++ "b/k8s\350\257\246\347\273\206\346\225\231\347\250\213-\350\260\203\346\225\264\347\211\210/metallb;ingress-nginx\351\203\250\347\275\262" @@ -0,0 +1,74 @@ +https://blog.51cto.com/u_15127525/2658808 +K8S v1.18.x 部署-Kubeadm方式-7:部署Addon-MetalLB +MetalLB +MetalLB , 通过K8S原生的方式提供LB类型的Service支持,开箱即用。 + +MetalLB在Kubernetes内运行,监控服务对象的变化,一旦察觉有新的LoadBalancer服务运行,并且没有可申请的负载均衡器之后,就会完成两部分的工作: + +地址分配 +用户需要在配置中提供一个地址池,MetalLB将会在其中选取地址分配给该服务。 + +地址广播 +根据不同配置,MetalLB会以二层(ARP/NDP)或者BGP的方式进行地址的广播。 + +支持范围 +Calico: 部分支持 +Canel: 支持 +Flannel: 支持 +Kube-router: 部分支持 +Romana: 支持 +Weave Net: 部分支持 + + +工作模式 +Layer2模式 +MetalLB在这种模式下,只需要一段跟K8S管理网相同网段的地址即可。 + +MetalLB会从K8S节点中选一个Leader节点,在这个节点上面响应LB地址段的ARP请求,从而使上层路由把发往LB的流量都发到Leader节点。 + +缺点也很明显,所有对LB的请求都会发往Leader节点。如果当前Service下面的Pod分布在不同节点,那么这个流量还会从Leader发往相应的节点。 + +不过用在实验环境里这个模式不需要路由器支持BGP。 +图片来源: https://zhuanlan.zhihu.com/p/103717169 + +BGP模式 +跟L2模式的区别就是能够通过BGP协议正确分布流量了,不再需要一个Leader节点。 + +这种模式需要路由器支持接收MetalLB的BGP广播,从而把请求分布到正确的节点上。 + +缺点就是需要上层路由器支持BGP。而且因为BGP单Session的限制,如果Calico也是使用的BGP模式,就会有冲突从而导致MetalLB无法正常工作。 +图片来源: https://zhuanlan.zhihu.com/p/103717169 + +部署MetalLB +如果kube-proxy启用了IPVS,需要设置strictARP: true。 + + +[root@K8S-PROD-M1 ~]# kubectl edit configmap -n kube-system kube-proxy +... + ipvs: + excludeCIDRs: null + minSyncPeriod: 5s + scheduler: wrr + strictARP: true #将false设置成true + syncPeriod: 5s + tcpFinTimeout: 0s + tcpTimeout: 0s + udpTimeout: 0s + kind: KubeProxyConfiguration + metricsBindAddress: "" + mode: ipvs +... + +或者使用下面的方法: + +# see what changes would be made, returns nonzero returncode if different +kubectl get configmap kube-proxy -n kube-system -o yaml | \ +sed "s/strictARP: false/strictARP: true/" | \ +kubectl diff -f - -n kube-system + +# actually apply the changes, returns nonzero returncode on errors only +kubectl get configmap kube-proxy -n kube-system -o yaml | \ +sed -i "s/strictARP: false/strictARP: true/" | \ +kubectl apply -f - -n kube-system + + -- Gitee