Red Hat OpenShift on IBM Cloud (ROKS) oc コマンドによる Worker Pool 関連情報の確認

Red Hat OpenShift on IBM Cloud (ROKS) には、OpenShift における Worker Node の上位概念として Worker Pool が存在します。ROKS 利用者は、Worker Pool の作成に際して Flavor や VLAN 等を設定することで、ワークロード要件を満たした Worker Node を実装 (Deploy) します。

Worker Pool に関する情報は、ROKS の Portal 画面や `ibmcloud oc worker-pool` コマンドで確認します。
https://cloud.ibm.com/docs/openshift?topic=openshift-kubernetes-service-cli#worker-pool

```shell
$ ibmcloud plugin list
Listing installed plug-ins...

Plugin Name                             Version   Status   Private endpoints supported
container-service[kubernetes-service]   1.0.408            false

$ ibmcloud oc worker-pool help
NAME:
        ibmcloud ks worker-pool - View and modify worker pools for a cluster.
USAGE:
        ibmcloud ks worker-pool command [arguments...] [command options]

COMMANDS:
    create      Add a worker pool to a cluster. No worker nodes are created until zones are added to the worker pool.
    get         List the details of a worker pool.
    label       Set and remove custom Kubernetes labels for all worker nodes in a worker pool.
    ls          List all worker pools in a cluster.
    rebalance   Rebalance a worker pool in a cluster. Rebalancing adds worker nodes so that the worker pool has the same number of nodes per zone that you specified.
    resize      Resize the worker pool to the number of workers per zone that you specify.
    rm          Remove a worker pool from a cluster.
    taint       Set and remove Kubernetes taints for all worker nodes in a worker pool.
    zones       View the zones attached to a worker pool.


Enter 'ibmcloud ks worker-pool help [command]' for more information about a command.
```
<BR>

一方、OpenShift の各種操作は OpenShift Console や `oc` コマンドを使用します。ここでは、 `oc` コマンドで Worker Node に関連する Worker Pool の各種情報を確認する方法をご紹介します。

#### Worker Pool 関連情報の確認
Worker Pool 関連情報は、Worker Node の Label ( .metadata.labels ) で確認することが可能です。
```shell
$ oc get node -o name
node/90.131.311.131
node/90.131.311.132
node/90.131.311.133
node/90.131.311.136
node/90.131.311.142
node/90.131.311.145
node/90.131.311.155
node/90.131.311.165
node/90.131.311.167
node/90.131.311.169
node/90.131.311.171
node/90.131.311.182
node/90.131.311.183
node/90.131.311.186

$ oc get node/90.131.311.131 -o jsonpath='{.metadata.labels}' | jq -r .
{
  "arch": "amd64",
  "beta.kubernetes.io/arch": "amd64",
  "beta.kubernetes.io/instance-type": "mb4c.20x192.encrypted",
  "beta.kubernetes.io/os": "linux",
  "failure-domain.beta.kubernetes.io/region": "au-syd",
  "failure-domain.beta.kubernetes.io/zone": "syd04",
  "ibm-cloud.kubernetes.io/encrypted-docker-data": "true",
  "ibm-cloud.kubernetes.io/external-ip": "192.168.332.25",
  "ibm-cloud.kubernetes.io/iaas-provider": "softlayer",
  "ibm-cloud.kubernetes.io/internal-ip": "90.131.311.131",
  "ibm-cloud.kubernetes.io/machine-type": "mb4c.20x192.encrypted",
  "ibm-cloud.kubernetes.io/os": "REDHAT_7_64",
  "ibm-cloud.kubernetes.io/region": "au-syd",
  "ibm-cloud.kubernetes.io/sgx-enabled": "false",
  "ibm-cloud.kubernetes.io/worker-id": "kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000dca",
  "ibm-cloud.kubernetes.io/worker-pool-id": "c9ecepez0ho14k0xyq10-9de66b6",
  "ibm-cloud.kubernetes.io/worker-pool-name": "mypool1",
  "ibm-cloud.kubernetes.io/worker-version": "4.6.56_1579_openshift",
  "ibm-cloud.kubernetes.io/zone": "syd04",
  "kubernetes.io/arch": "amd64",
  "kubernetes.io/hostname": "90.131.311.131",
  "kubernetes.io/os": "linux",
  "node-role.kubernetes.io/master": "",
  "node-role.kubernetes.io/worker": "",
  "node.kubernetes.io/instance-type": "mb4c.20x192.encrypted",
  "node.openshift.io/os_id": "rhel",
  "privateVLAN": "0123456",
  "publicVLAN": "9876543",
  "topology.kubernetes.io/region": "au-syd",
  "topology.kubernetes.io/zone": "syd04"
}
```
なお、ROKS がデフォルトで設定する Label の削除はサポートされていません。
https://cloud.ibm.com/docs/containers?topic=containers-add_workers&locale=en#worker_pool_labels

:::note warn
Important: Do not remove the worker pool and worker node labels that are provided by mypool2 because these labels are required for worker pools to function properly. Remove only custom labels that you previously added..
:::

#### oc コマンドで Worker Pool 関連情報を表示する
`oc get node` コマンドで `-o custom-columns` または `-o custom-columns-file` オプションを使用します。
```shell
$ cat CustomColumnFile.txt
NAME REGION ZONE FLAVOR WORKER_ID WPOOL WPOOL_ID PRIVATE_VLAN PUBLIC_VLAN
.metadata.name .metadata.labels.ibm-cloud\.kubernetes\.io/region .metadata.labels.ibm-cloud\.kubernetes\.io/zone .metadata.labels.ibm-cloud\.kubernetes\.io/machine-type .metadata.labels.ibm-cloud\.kubernetes\.io/worker-id .metadata.labels.ibm-cloud\.kubernetes\.io/worker-pool-name .metadata.labels.ibm-cloud\.kubernetes\.io/worker-pool-id .metadata.labels.privateVLAN .metadata.labels.publicVLAN

$ oc get node -o custom-columns-file=CustomColumnFile.txt --sort-by=".metadata.labels.ibm-cloud\.kubernetes\.io/worker-pool-name"
NAME             REGION   ZONE    FLAVOR                  WORKER_ID                                         WPOOL      WPOOL_ID                       PRIVATE_VLAN   PUBLIC_VLAN
90.131.311.145   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000b53   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.171   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000c7e   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.133   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000857   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.165   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000a81   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.155   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000e76   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.131   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-00000dca   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.186   au-syd   syd04   mb4c.20x192.encrypted   kube-c9ecepez0ho14k0xyq10-roks-mypool1-000009e8   mypool1    c9ecepez0ho14k0xyq10-9de66b6   0123456        9876543
90.131.311.142   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-000007a4   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
90.131.311.167   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-0000038a   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
90.131.311.169   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-000001f5   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
90.131.311.132   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-000002ad   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
90.131.311.182   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-00000509   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
90.131.311.183   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-000004b0   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
90.131.311.136   au-syd   syd04   m3c.16x128.encrypted    kube-c9ecepez0ho14k0xyq10-roks-mypool2-000006ed   mypool2    c9ecepez0ho14k0xyq10-30b0e45   0123456        9876543
```
<BR>
こうすることで、Worker Node と Worker Pool の関連を分かりやすく表示することが可能です。