kubectl config get-contexts and custom-columns output

Viewed 921

I would like kubectl config get-contexts to show all, or any arbitrary subset, of the columns shown in default output.

Currently, kubectl config get-contexts shows CURRENT NAME CLUSTER AUTHINFO and NAMESPACE. On my terminal, that's a total of 221 columns, with NAME, CLUSTER, and AUTHINFO being identical for all contexts.

kubectl config get-contexts documentation shows only one output option: -o=name. Attempts to override this with -o=custom-columns="CURRENT:.metadata.current,NAME:.metadata.name" (for example) result in an error.

Am I doing something wrong or is the custom-columns option that is common to kubectl get a missing feature?

Update: maintainers decided that there was no clean way of implementing output options; see https://github.com/kubernetes/kubectl/issues/1052

1 Answers

As indicated by the error message:

error: output must be one of '' or 'name'

and described in the docs:

output  o       Output format. One of: name

only the value of name can be used with the custom-columns option for kubectl config get-contexts.

The other option that you have left is to list the current context with:

kubectl config current-context 
Related