接着上文,排除故障后,我重新配置了metallb组件到k8s环境,
为k8s service 的loadbalance负载方式提供免费的解决方案(external-ip的收费方案,可以选择GRE或Azure,或其他国内云商LB方案)
以下是详细安装和配置步骤,最后附上效果截图。
step 1:
root >> kubectl apply -f \
root >> kubectl get all -n metallb-system
step 2:
# 生成一个configmap,
# 注意:这里的 IP 地址范围需要跟集群实际情况相对应。
root >> kubectl apply -f - << EOF apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | peers: # Cosmetic edit to make MetalLB notice that this is a new config. - my-asn: 64512 peer-asn: 64512 peer-address: 10.4.0.100 - my-asn: 64512 peer-asn: 64512 peer-address: 10.4.0.101 - my-asn: 64512 peer-asn: 64512 peer-address: 10.4.0.102 address-pools: - name: my-ip-space protocol: bgp avoid-buggy-ips: true addresses: - 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服务和部署,如下
root >> kubectl apply -f - << EOF apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-lb namespace: app spec: selector: matchLabels: app: nginx-lb replicas: 1 template: metadata: labels: app: nginx-lb spec: containers: - name: nginx-lb image: nginx:1.7.9 ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: nginx-lb namespace: app spec: type: LoadBalancer ports: - port: 8090 targetPort: 80 selector: 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