add additional column to base kubectl get pods command

Viewed 1772

im trying to build a custom column query that we use all the time. what i want is to take this basic output:

NAME                               READY   STATUS    RESTARTS   AGE
mypod                              2/2     Running   4          2d3h

and simply add a column to it, all i want is to add NODE:.spec.nodeName to this table. I can't find the base column format for the above, does anyone know where i can find it? I tried searching in the kubectl source code, but that proved to be a bit of a challenge.

Where can i find this output pattern?

1 Answers

You can use the tag --custom-columns in kubectl command to get the nodeName:

-o=custom-columns=<spec> Print a table using a comma separated list of custom columns

For example:

kubectl get pods my-pod -o=custom-columns='DATA:spec.nodeName' will return the node name.

Here you can find more about the tag and see usage examples.

Related