如何在智能告警平台CA触发测试告警
980
2022-10-25
MetalLB — Kubernetes LoadBalancer服务
Kubernetes对外提供了三种访问方式,即NodePort、LoadBalancer和Ingress。其中LoadBalancer类型是提供给受支持的IaaS平台使用的(如GCP,AWS等公有云),在支持的平台中创建Service指定LoadBalancer类型,就可以外部访问,如不支持,EXTERNAL-IP会一直在pending的状态。
关于MetalLB
在裸机集群中的LoadBalancer,MetalLB可以为其分配EXTERNAL-IP. MetalLB旨在通过提供与标准网络设备集成的网络LB实现来纠正这种不平衡,以便裸机集群上的外部服务也“尽可能”地工作。
MetalLB有两种模式,layer 2和BGP。layer 2模式与Keepalived有很多相似之处,单节点瓶颈和潜在的故障转移速度很慢,而且并不是真正意义上的负载均衡,实际上通过一个节点去访问。BGP模式中群集中的每个节点都与网络路由器建立BGP对等会话,但是与CNI插件集成时有兼容性问题,且kube-proxy版本需要1.13以上。如果kube-proxy使用ipvs,则需要1.14.2版本以上。
安装
设置kube-proxy参数
mode: "ipvs"ipvs: strictARP: true
使用 yaml 部署:
kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.9.3/manifests/namespace.yamlkubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.9.3/manifests/metallb.yaml
使用 helm 部署:
helm install --name metallb stable/metallb
查看MetalLB状态
[root@kube-master01 ~]# kubectl get node -o wideNAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIMEkube-master01 Ready master 22h v1.18.0 172.31.209.239
MetalLB配置
layer 2模式
[root@kube-master01 metallb]# cat metallb-config-layer2.yamlapiVersion: v1kind: ConfigMapmetadata: namespace: metallb-system name: configdata: config: | address-pools: - name: default protocol: layer2 addresses: - 10.233.9.100-10.233.9.250[root@kube-master01 metallb]#
BGP模式
BGP模式需要4条信息
MetalLB应连接的路由器IP地址;
路由器的AS号;
MetalLB应该使用的AS编号;
IP地址范围,表示为CIDR前缀;
例如为MetalLB提供范围10.233.9.0/24和AS号64500,并将其连接到10.0.0.1的AS号为64501的路由器
[root@kube-master01 metallb]# cat metallb-config-bgp.yamlapiVersion: v1kind: ConfigMapmetadata: namespace: metallb-system name: configdata: config: | peers: - peer-address: 10.0.0.1 peer-asn: 64501 my-asn: 64500 address-pools: - name: default protocol: bgp addresses: - 10.233.9.0/24 bgp-advertisements: - aggregation-length: 32 localpref: 100 communities: - no-advertise - aggregation-length: 24 bgp-communities: no-advertise: 65535:65282[root@kube-master01 metallb]#
测试
为NGINX创建LoadBalancer类型的Service
[root@kube-master01 metallb]# kubectl get pod,svc NAME READY STATUS RESTARTS AGEpod/busybox 1/1 Running 0 17hpod/nginx-6df6d6b46f-tcxjg 1/1 Running 0 17hpod/nginx-6df6d6b46f-zzhlk 1/1 Running 0 17hNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 10.254.0.1
查看MetalLB分配的EXTERNAL-IP
[root@kube-master01 ~]# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.254.0.1 If you see this page, the nginx web server is successfully installed andworking. Further configuration is required. For online documentation and support please refer tonginx.org. Thank you for using nginx.Welcome to nginx!
Commercial support is available atnginx.com.
发表评论
暂时没有评论,来抢沙发吧~