“Kubernetes的负载均衡器真的能实现负载均衡吗?我忍不住要试一试。”
你好,我是Class Act Infrastructures事业部的大塚先生。
更改HTML文件
root@k8s-master:~# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-httpd-deployment-759b9b5f-vq8rp 2/2 Running 0 3h5m 10.1.235.209 k8s-master <none> <none>
nginx-httpd-deployment-759b9b5f-rsp86 2/2 Running 0 3h5m 10.1.79.68 k8s-worker01 <none> <none>
nginx-httpd-deployment-759b9b5f-h8k67 2/2 Running 0 3h5m 10.1.69.197 k8s-worker02 <none> <none>
root@k8s-master:~# kubectl exec -it nginx-httpd-deployment-759b9b5f-vq8rp -c web-httpd -- /bin/bash
root@nginx-httpd-deployment-759b9b5f-vq8rp:/usr/local/apache2# cd /usr/local/apache2/htdocs
root@nginx-httpd-deployment-759b9b5f-vq8rp:/usr/local/apache2/htdocs# vi index.html
root@nginx-httpd-deployment-759b9b5f-vq8rp:/usr/local/apache2/htdocs# cat index.html
<html><body><h1>It works on master!!</h1></body></html>
root@nginx-httpd-deployment-759b9b5f-vq8rp:/usr/local/apache2/htdocs# /usr/local/apache2/bin/apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.235.209. Set the 'ServerName' directive globally to suppress this message
root@k8s-master:~# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-httpd-deployment-759b9b5f-vq8rp 2/2 Running 0 3h7m 10.1.235.209 k8s-master <none> <none>
nginx-httpd-deployment-759b9b5f-rsp86 2/2 Running 0 3h7m 10.1.79.68 k8s-worker01 <none> <none>
nginx-httpd-deployment-759b9b5f-h8k67 2/2 Running 0 3h7m 10.1.69.197 k8s-worker02 <none> <none>
root@k8s-master:~# kubectl exec -it nginx-httpd-deployment-759b9b5f-rsp86 -c web-httpd -- /bin/bash
root@nginx-httpd-deployment-759b9b5f-rsp86:/usr/local/apache2# cd /usr/local/apache2/htdocs
root@nginx-httpd-deployment-759b9b5f-rsp86:/usr/local/apache2/htdocs# vi index.html
root@nginx-httpd-deployment-759b9b5f-rsp86:/usr/local/apache2/htdocs# cat index.html
<html><body><h1>It works on worker01!!</h1></body></html>
root@nginx-httpd-deployment-759b9b5f-rsp86:/usr/local/apache2/htdocs# /usr/local/apache2/bin/apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.79.68. Set the 'ServerName' directive globally to suppress this message
root@k8s-master:~# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-httpd-deployment-759b9b5f-vq8rp 2/2 Running 0 3h9m 10.1.235.209 k8s-master <none> <none>
nginx-httpd-deployment-759b9b5f-rsp86 2/2 Running 0 3h9m 10.1.79.68 k8s-worker01 <none> <none>
nginx-httpd-deployment-759b9b5f-h8k67 2/2 Running 0 3h9m 10.1.69.197 k8s-worker02 <none> <none>
root@k8s-master:~# kubectl exec -it nginx-httpd-deployment-759b9b5f-h8k67 -c web-httpd -- /bin/bash
root@nginx-httpd-deployment-759b9b5f-h8k67:/usr/local/apache2# cd /usr/local/apache2/htdocs
root@nginx-httpd-deployment-759b9b5f-h8k67:/usr/local/apache2/htdocs# vi index.html
root@nginx-httpd-deployment-759b9b5f-h8k67:/usr/local/apache2/htdocs# cat index.html
<html><body><h1>It works on worker02!!</h1></body></html>
root@nginx-httpd-deployment-759b9b5f-h8k67:/usr/local/apache2/htdocs# /usr/local/apache2/bin/apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.69.197. Set the 'ServerName' directive globally to suppress this message
做实验
LoadBalancer工作正常,經多次連接發現即使使用相同的IP地址和埠號,輸出的內容也有所不同。