2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「KubernetesのLoadBalancerって本当に負荷分散してるの~?」試さずにはいられない

Last updated at Posted at 2023-05-03

こんにちは
株式会社クラスアクト インフラストラクチャ事業部の大塚です。

今回はmicrok8sで構築した以下環境で本当に負荷分散されているのかを確認してみたいと思います。
具体的にはそれぞれのnode上にいるpod内のapache2のhtmlファイルをそれぞれ固有のものに変更。何度かLoadBalancerのIPアドレス:9090ポートにWebブラウジングして出力される内容変わるよね~ってことを確認します。
k8s-ページ28.drawio.png

htmlファイルの変更

nginx-httpd-deployment-759b9b5f-vq8rpのweb-httpdコンテナ
黄色枠内のpod/コンテナのhtmlを修正します。
k8s-ページ30.drawio.png

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

nginx-httpd-deployment-759b9b5f-rsp86のweb-httpdコンテナ
黄色枠内のpod/コンテナのhtmlを修正します。
k8s-ページ30.drawio (1).png

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

nginx-httpd-deployment-759b9b5f-h8k67のweb-httpdコンテナ
黄色枠内のpod/コンテナのhtmlを修正します。
k8s-ページ30.drawio (2).png

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

実験

何度か接続を繰り返しました。
同じIPアドレスとポート番号ですが、出力されている内容が変わっていることが分かります。
LoadBalancerはちゃんと仕事をしていますね。

aaaaaa.png

bbbbbb.png

cccccc.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?