部署metallb
官方部署metallb文档:
https://metallb.universe.tf/tutorial/layer2/
项目地址:
https://github.com/google/metallb:
部署metallb负载均衡器
$ wget https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml
先拉取镜像
$ docker pull metallb/speaker:v0.8.2
$ docker pull metallb/controller:v0.8.2
$ kubectl apply -f metallb.yaml
查看运行的pod
metalLB包含两个部分: a cluster-wide controller, and a per-machine protocol speaker
[root@master yaml-resource]# kubectl get pod -n metallb-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
controller-65895b47d4-569qt 1/1 Running 0 28s 10.244.0.8 master <none> <none>
speaker-7hjpq 1/1 Running 0 28s 192.168.1.93 master <none> <none>
speaker-wktjz 1/1 Running 0 28s 192.168.1.92 node <none> <none>
查看其它信息
包含了 “controller” deployment,和 the “speaker” DaemonSet.
[root@master yaml-resource]# kubectl get daemonset -n metallb-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
speaker 2 2 2 2 2 beta.kubernetes.io/os=linux 2m45s
[root@master yaml-resource]# kubectl get deployment -n metallb-system
NAME READY UP-TO-DATE AVAILABLE AGE
controller 1/1 1 1 3m10s
目前还没有宣布任何内容,因为我们没有提供ConfigMap,也没有提供负载均衡地址的服务。
接下来我们要生成一个 Configmap 文件,为 Metallb 设置网址范围以及协议相关的选择和配置,这里以一个简单的二层配置为例。
创建config.yaml提供IP池
wget https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/example-layer2-config.yaml
修改ip地址池和集群节点网段相同
[centos@k8s-master ~]$ vim example-layer2-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.1.150-192.168.1.200
注意:这里的 IP 地址范围需要跟集群实际情况相对应。
执行yaml文件
$ kubectl apply -f example-layer2-config.yaml
-------------------------------------------------------------
创建后端应用和服务测试
$ wget https://raw.githubusercontent.com/google/metallb/master/manifests/tutorial-2.yaml
$ kubectl apply -f tutorial-2.yaml
查看yaml文件配置,包含了一个deployment和一个LoadBalancer类型的service,默认即可。
(修改了一下nginx的镜像,原写法nginx:l, 改为nginx:latest)
执行报错, 修改apps/v1beta2为apps/v1
------
查看service分配的EXTERNAL-IP
[root@master yaml-resource]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana LoadBalancer 10.98.25.153 192.168.1.151 3000:31595/TCP 22h
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d3h
mysql ClusterIP 10.106.209.38 <none> 3306/TCP 18h
nginx LoadBalancer 10.103.191.109 192.168.1.153 80:30776/TCP 26h
prometheus ClusterIP 10.101.40.175 <none> 9090/TCP 22h
prometheus-proxy LoadBalancer 10.105.193.116 192.168.1.150 8080:30345/TCP,7001:31165/TCP 22h
scdf-server LoadBalancer 10.96.195.218 192.168.1.152 80:31348/TCP 3h45m
在浏览器中测试nginx
http://192.168.1.153
正常返回
在192.168.1.93(master)无法ping通
192.168.1.153:30776 无法访问