Skip to content
pipefail

Get Kubernetes Nodes and Pods with Custom Columns Using kubectl

kubernetes, kubectl, aws1 min read

kubectl has so many ways that you can format and customize output, it can be overwhelming. One of my favorite ways to customize node output is the custom-columns option. With this option you can tell kubectl exactly what columns you want in your kubectl get nodes output.

For example, if you wanted to only get the name of your nodes plus a couple of labels you could use the below to specify only those columns.

1kubectl get no -o=custom-columns=NAME:.metadata.name,"MY CUSTOM LABEL":".metadata.labels.me/my-custom-label","AWS NODE SIZE":".metadata.labels.beta\.kubernetes\.io/instance-type"
2NAME
3
4NAME MY CUSTOM LABEL AWS NODE SIZE
5ip-10-10-1-123.ec2.internal value1 t3.large
6ip-10-10-1-124.ec2.internal <none> t3.large
7ip-10-10-1-125.ec2.internal value2 t3.large
8ip-10-10-1-126.ec2.internal value2 r5a.large
9ip-10-10-2-127.ec2.internal value2 r5a.large

A couple of notes here:

  • This example assumes EKS for the metadata.labels.beta.kubernetes.io/instance-type label, so adjust accordingly for whatever columns you'd like to retrieve.
  • Be sure to escape the periods in any of the fields that you'd like to retrieve, like .metadata.labels.beta\.kubernetes\.io/instance-type.
  • Also try the custom-columns option with pods!