[root@lee ~]# kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml namespace/metallb-system created serviceaccount/controller created serviceaccount/speaker created clusterrole.rbac.authorization.k8s.io/metallb-system:controller created clusterrole.rbac.authorization.k8s.io/metallb-system:speaker created role.rbac.authorization.k8s.io/config-watcher created clusterrolebinding.rbac.authorization.k8s.io/metallb-system:controller created clusterrolebinding.rbac.authorization.k8s.io/metallb-system:speaker created rolebinding.rbac.authorization.k8s.io/config-watcher created daemonset.apps/speaker created deployment.apps/controller created
[root@lee ~]# kubectl get pods -n metallb-system -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE controller-765899887-bdwdk 1/1 Running 0 82s 10.0.0.22 lee <none> speaker-qldl6 1/1 Running 0 82s 192.168.50.124 lee <none>
[root@lee ~]# kubectl get svc -owide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR nginx LoadBalancer 10.0.228.36 192.168.50.211 80:31796/TCP 65s app=nginx
ping 该 EXTERNAL-IP 地址,发现该地址可以访问了
[root@lee ~]# ping 192.168.50.211 PING 192.168.50.211 (192.168.50.211) 56(84) bytes of data. 64 bytes from 192.168.50.211: icmp_seq=1 ttl=64 time=0.050 ms 64 bytes from 192.168.50.211: icmp_seq=2 ttl=64 time=0.082 ms 64 bytes from 192.168.50.211: icmp_seq=3 ttl=64 time=0.068 ms
集群内访问该 EXTERNAL-IP 地址
[root@lee ~]# curl 192.168.50.211 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ............... <p><em>Thank you for using nginx.</em></p> </body> </html>
从集群外访问该 IP 地址
Administrator at 16:47:09 / $ curl 192.168.50.211 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 612 100 612 0 0 597k 0 --:--:-- --:--:-- --:--:-- 597k<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ................ <p><em>Thank you for using nginx.</em></p> </body> </html>
另外使用 Node IP + NodePort 也可以访问
Administrator at 16:47:09 / $ curl 192.168.50.124:31796 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 612 100 612 0 0 597k 0 --:--:-- --:--:-- --:--:-- 597k<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ................ <p><em>Thank you for using nginx.</em></p> </body> </html>