Today I Learnt FM
On , I learnt ...
How to include AWS-specific info when using kubectl get nodes

The standard configuration when using kubectl get nodes is meant to be working for any cluster, therefore does not include any specific information about the K8s distribution you are using.

At work we are big users of AWS, and we are running many EKS clusters. Clusters with multiple nodegroups, each one with different launch templates which brings nodes up with different security groups attached.

Sometimes it is difficult to print all this information. kubectl has a custom-columns output that is helpful in the case you want to print AWS specific information. Here’s an example:

> k get nodes -o,INSTANCE_TYPE:".metadata.labels.node\.kubernetes\.io/instance-type",EKS_NODEGROUP:".metadata.labels.eks\.amazonaws\.com/nodegroup",READY:".status.conditions[?(@.reason=='KubeletReady')].status",CREATED_AT:".metadata.creationTimestamp"

NAME                                            INSTANCE_TYPE   EKS_NODEGROUP                              READY   CREATED_AT   m5.2xlarge      br_privileged-20220525160725365900000001   True    2022-11-12T11:06:45Z   m5.large        br_default-20220525160725393100000003      True    2022-11-07T10:31:33Z    m5.large        br_default-20220525160725393100000003      True    2022-05-25T16:08:34Z   m5.2xlarge      br_privileged-20220525160725365900000001   True    2022-11-12T10:37:09Z   m5.large        br_default-20220525160725393100000003      True    2022-10-28T03:56:19Z

The above command prints instance types and node groups. More data is injected by AWS as a node label. You can decide what to pull by picking it from the kubectl describe node output:

Roles:              <none>

In the case of AWS, the node name is not particularly useful. You can change it for the instance id:

> k get nodes -o custom-columns=INSTANCE_ID:.spec.providerID,INSTANCE_TYPE:".metadata.labels.node\.kubernetes\.io/instance-type",EKS_NODEGROUP:".metadata.labels.eks\.amazonaws\.co
Kubeconfig user entry is using deprecated API version Run 'aws eks update-kubeconfig' to update.
INSTANCE_ID                                  INSTANCE_TYPE   EKS_NODEGROUP                              READY   CREATED_AT
aws:///ap-northeast-1a/i-09603471464edb7d4   m5.2xlarge      br_privileged-20220906113602961400000001   True    2022-11-25T03:33:23Z
aws:///ap-northeast-1a/i-0926e1e0ab36e7d29   m5.large        br_default-20220808183837971200000013      True    2022-11-21T11:15:26Z
aws:///ap-northeast-1a/i-070e1e9afb1c5e5e8   m5.large        br_default-20220808183837971200000013      True    2022-10-28T03:52:51Z
aws:///ap-northeast-1a/i-0d2a323d4fa70b08d   m5.large        br_default-20220808183837971200000013      True    2022-10-27T12:46:56Z
aws:///ap-northeast-1a/i-0e8404aea87c57624   m5.2xlarge      br_privileged-20220906113602961400000001   True    2022-11-25T10:55:28Z
aws:///ap-northeast-1a/i-04a0f5e5edfd58374   m5.2xlarge      br_privileged-20220906113602961400000001   True    2022-11-25T10:16:36Z