動作確認として、取得したkubeconfigを利用して接続した環境に対して、podを作成し外部から接続
※テスト環境用namespace作成 [root@localhost .kube]# kubectl create namespace ns01 namespace/ns01 created ※pod(nginx)作成 [root@localhost .kube]# kubectl -n ns01 run nginx --image=nginx pod/nginx created ※podが作成され、稼働していることを確認 [root@localhost .kube]# kubectl -n ns01 get pod -o wide --show-labels NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS nginx 1/1 Running 0 110s 100.96.1.16 tkg01-worker-node-pool-1-6cd5656db6xb5xb9-zhc8v <none> <none> run=nginx ※service作成 [root@localhost .kube]# kubectl -n ns01 create service loadbalancer ng-lb --tcp=80 --dry-run -o yaml 出力結果のうちselector箇所をpodのラベルと同一に修正した内容にてファイル(lb.yml)作成 [root@localhost .kube]# kubectl apply -f lb.yml service/ng-lb created ※service確認 [root@localhost .kube]# kubectl -n ns01 get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ng-lb LoadBalancer 100.67.88.27 10.1.0.123 80:30303/TCP 31s ※EXTERNAL-IPへ接続確認 [root@localhost .kube]# curl http://10.1.0.123 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
ファイル内容
[root@localhost .kube]# cat lb.yml apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: app: ng-lb name: ng-lb namespace: ns01 spec: ports: - name: "80" port: 80 protocol: TCP targetPort: 80 selector: run: nginx ←ここだけ変更 type: LoadBalancer status: loadBalancer: {}