Skip to main content
duffn.dev

Get Kubernetes Nodes and Pods with Custom Columns Using kubectl

Share: 

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.

kubectl 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"
NAME

NAME MY CUSTOM LABEL AWS NODE SIZE
ip-10-10-1-123.ec2.internal value1 t3.large
ip-10-10-1-124.ec2.internal <none> t3.large
ip-10-10-1-125.ec2.internal value2 t3.large
ip-10-10-1-126.ec2.internal value2 r5a.large
ip-10-10-2-127.ec2.internal value2 r5a.large

A couple of notes here: