vSphere with Kubernetes ラボ環境構築。Part-14: Tanzu Kubernetes Cluster への接続 / Pod 起動編

vSphere with Kubernetes ラボ環境構築。Part-14: Tanzu Kubernetes Cluster への接続 / Pod 起動編

前回は、vSphere with Kubernetes のラボ環境で、Tanzu Kubernetes Cluster を作成しました。

前回はこちら。

vSphere with Kubernetes ラボ環境構築。Part-13: Supervisor Namespace での Tanzu Kubernetes Cluster 作成編

今回は、作成した Tanzu Kubernetes Cluster に接続して、Pod を起動してみます。

Tanzu Kubernetes Cluster は作成ずみです。

※なお、前回の手順で作成していますが、再作成しているのでノードの名前が異なります。

wcp-14-01.png

Tanzu Kubernetes Cluster への接続。

kubectl で、Tanzu Kubernetes Cluster に接続します。

vSphere 専用の kubectl の準備については、下記の投稿のようにしています。

vSphere with Kubernetes ラボ環境構築。Part-11: kubectl で vSphere Pod 起動編

login では、Supervisor Cluster に接続する場合のコマンドラインに、

追加で下記のオプションを指定しています。

  • --tanzu-kubernetes-cluster-namespace=lab-ns-02
  • --tanzu-kubernetes-cluster-name=tkg-cluster-01

Tanzu Kubernetes Cluster の名前は、名前空間ごとに一意になるので、

「--tanzu-kubernetes-cluster-name」だけでなく、

名前空間の名前「--tanzu-kubernetes-cluster-namespace」も指定する必要があります。

$ kubectl vsphere login --insecure-skip-tls-verify --server=192.168.70.33 --tanzu-kubernetes-cluster-namespace=lab-ns-02 --tanzu-kubernetes-cluster-name=tkg-cluster-01

Username: administrator@vsphere.local

Password: ★パスワード入力

Logged in successfully.

You have access to the following contexts:

   192.168.70.33

   lab-ns-01

   lab-ns-02

   tkg-cluster-01

If the context you wish to use is not in this list, you may need to try

logging in again later, or contact your cluster administrator.

To change context, use `kubectl config use-context <workload name>`

$

Kubernetes クラスタを構成するノードの確認。

context  を明示的に指定して get nodes でノードの確認をしてみます。

Tanzu Kubernetes Cluster では、下記のように、デプロイされた VM によって、

Supervisor Cluster とは別の Kubernetes クラスタが構成されていることが分かります。

$ kubectl --context tkg-cluster-01 get nodes

NAME                                            STATUS   ROLES    AGE   VERSION

tkg-cluster-01-control-plane-5w6vn              Ready    master   13h   v1.16.8+vmware.1

tkg-cluster-01-control-plane-p89lb              Ready    master   12h   v1.16.8+vmware.1

tkg-cluster-01-control-plane-phd6l              Ready    master   12h   v1.16.8+vmware.1

tkg-cluster-01-workers-l6qtc-586578bd88-5d7kh   Ready    <none>   12h   v1.16.8+vmware.1

tkg-cluster-01-workers-l6qtc-586578bd88-czrpg   Ready    <none>   12h   v1.16.8+vmware.1

tkg-cluster-01-workers-l6qtc-586578bd88-vk6f8   Ready    <none>   12h   v1.16.8+vmware.1

あらためて、Tanzu Kubernetes Cluster(tkg-cluster-01)の外側の context(lab-ns-02 名前空間と同名)を指定して、

Kubernetes ノードを確認しておきます。

こちらは、ESXi と Supervisor Control Plane VM で、Kubernetes のクラスタが構成されています。

$ kubectl --context lab-ns-02 get nodes

NAME                               STATUS   ROLES    AGE   VERSION

422c6912a62eabbf0a45c417405308c9   Ready    master   67d   v1.17.4-2+a00aae1e6a4a69

422c9d9222c60e5328cdc12a543c099a   Ready    master   67d   v1.17.4-2+a00aae1e6a4a69

422cfbc654627c47880a2ec7ae144424   Ready    master   67d   v1.17.4-2+a00aae1e6a4a69

lab-wcp-esxi-031.go-lab.jp         Ready    agent    67d   v1.17.4-sph-091e39b

lab-wcp-esxi-032.go-lab.jp         Ready    agent    67d   v1.17.4-sph-091e39b

lab-wcp-esxi-033.go-lab.jp         Ready    agent    67d   v1.17.4-sph-091e39b

Tanzu Kubernetes Cluster での Pod 起動。

以前に vSphere Pod を起動した YAML ファイルで、

tkg-cluster-01 上に Pod を起動してみます。

YAML ファイルの内容は、下記のようになっています。

$ cat nginx-pod.yml

---

kind: Pod

apiVersion: v1

metadata:

  name: nginx-pod

  labels:

    app: wcp-demo

spec:

  containers:

  - image: nginx

    name: nginx-container

kubectl で操作する context を tkg-cluster-01 に切り替えます。

$ kubectl config use-context tkg-cluster-01

Switched to context "tkg-cluster-01".

それでは、Pod を起動します。

$ kubectl apply -f nginx-pod.yml

pod/nginx-pod created

tkg-cluster-01 クラスタのノード(tkg-cluster-01-workers-~)で起動されました。

$ kubectl get pods -o wide

NAME        READY   STATUS    RESTARTS   AGE   IP            NODE                                            NOMINATED NODE   READINESS GATES

nginx-pod   1/1     Running   0          40s   192.0.175.2   tkg-cluster-01-workers-l6qtc-586578bd88-vk6f8   <none>           <none>

一方、vSphere Client で確認すると、(vSphere Pod の場合ような)Pod の確認はできません。

vSphere Pod の場合には、インベントリや下記の赤枠のあたりで、起動された Pod が表示されていました。

しかし、Tanzu Kubernetes Cluster の Pod(そして他の Kubernete リソースも)は、

この「コア Kubernetes」の画面には表示されません。

wcp-14-02.png

これは、Pod が VM(この環境では、「tkg-cluster-01-workers-~」)の内部で起動されているためです。

vSphere Pod は、Pod が特殊な VM として作成されるので vSphere Client での視認性がよかったのですが、

Tanzu Kubernetes Cluster では、よくある「Docker をインストールした VM」と同様、

Pod がコンテナホストになる VM の内部で起動されるので、

特に「vSphere ならではの見やすさ」はありません。

そこで、リソースの確認には Octant(https://github.com/vmware-tanzu/octant)などの

Kubernetes 可視化ツールがあると便利です。

まだ続きそう。

vSphere with Kubernetes ラボ環境構築。Part-15: Tanzu Kubernetes Cluster での PSP 使用 / Deployment 作成編

Version history
Revision #:
1 of 1
Last update:
‎07-30-2020 10:43 AM
Updated by: