当前位置:Gxlcms > 数据库问题 > K8S LoadBalance 私有环境解决方案 == metallb 工具安装和使用介绍

K8S LoadBalance 私有环境解决方案 == metallb 工具安装和使用介绍

时间:2021-07-01 10:21:17 帮助过:33人阅读

root >> kubectl apply -f \ https://raw.githubusercontent.com/danderson/metallb/main/manifests/metallb.yaml root >> kubectl get all -n metallb-system

技术图片

 

step 2: # 生成一个configmap, # 注意:这里的 IP 地址范围需要跟集群实际情况相对应。 # https://github.com/danderson/metallb/tree/main/manifests # https://github.com/danderson/metallb/blob/main/manifests/tutorial-4.yaml
  1. root >> kubectl apply -f - << EOF
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. namespace: metallb-system
  6. name: config
  7. data:
  8. config: |
  9. peers:
  10. # Cosmetic edit to make MetalLB notice that this is a new config.
  11. - my-asn: 64512
  12. peer-asn: 64512
  13. peer-address: 10.4.0.100
  14. - my-asn: 64512
  15. peer-asn: 64512
  16. peer-address: 10.4.0.101
  17. - my-asn: 64512
  18. peer-asn: 64512
  19. peer-address: 10.4.0.102
  20. address-pools:
  21. - name: my-ip-space
  22. protocol: bgp
  23. avoid-buggy-ips: true
  24. addresses:
  25. - 10.5.0.0/24

# 执行完毕如下图

技术图片

# 然后,我们在k8s物理机器的外网(比如我这里一台客户机192.168.3.XX),访问上面configmap的四个IP <1> IP_1 = 10.4.0.100 / 10.4.0.101 / 10.4.0.101 <2> IP_2 = 10.5.0.0/24 ==> 10.5.0.1 (也可以通过查询k8s service得到, kubectl get service --all-namespaces -o wide。) root >> ping 10.4.0.100 -c 3 root >> ping 10.4.0.101 -c 3 root >> ping 10.4.0.102 -c 3 root >> ping 10.5.0.1 -c 3 技术图片

 

step 3: # 查看配置过程 # pod名称,来自step 1查询pod结果 root >> kubectl get all -n metallb-system root >> kubectl logs -f controller-5f898b44f4-4pkk6 -n metallb-system 技术图片   step 4: # 创建一个私有loadbalance provider的nginx服务和部署,如下
  1. root >> kubectl apply -f - << EOF
  2. apiVersion: extensions/v1beta1
  3. kind: Deployment
  4. metadata:
  5. name: nginx-lb
  6. namespace: app
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: nginx-lb
  11. replicas: 1
  12. template:
  13. metadata:
  14. labels:
  15. app: nginx-lb
  16. spec:
  17. containers:
  18. - name: nginx-lb
  19. image: nginx:1.7.9
  20. ports:
  21. - containerPort: 80
  22. ---
  23. apiVersion: v1
  24. kind: Service
  25. metadata:
  26. name: nginx-lb
  27. namespace: app
  28. spec:
  29. type: LoadBalancer
  30. ports:
  31. - port: 8090
  32. targetPort: 80
  33. selector:
  34. app: nginx-lb

 技术图片

  step 5 # 查看创建后的结果,如下图
root >> kubectl get all -n app -o wide 技术图片 # 测试一下nginx-lb的service,通过如下两个地址
<1> cluster_ip : service_port
root >> curl http://10.3.2.28:8090 
技术图片 <2> external_ip : service_port
root >> curl http://10.5.0.3:8090
技术图片

K8S LoadBalance 私有环境解决方案 == metallb 工具安装和使用介绍

标签:href   pac   deploy   logs   clust   man   beta   tps   select   

人气教程排行