Reputation: 24776
I just want to list pods with their .status.podIP
as an extra column.
It seems that as soon as I specify -o=custom-colums=
the default columns NAME, READY, STATUS, RESTARTS, AGE
will disappear.
The closest I was able to get is
kubectl get pod -o wide -o=custom-columns="NAME:.metadata.name,STATUS:.status.phase,RESTARTS:.status.containerStatuses[0].restartCount,PODIP:.status.podIP"
but that is not really equivalent to the the default columns in the following way:
2/2
or 0/1
by using custom columns.status.phase
will never be Evicted
. It seems that the default STATUS is a combination of .status.phase
and .status.reason
. Is there a way to say show .status.phase
if it's Running but if not show .status.reason
?Does anybody know the definitions of the default columns in custom-columns syntax?
Upvotes: 16
Views: 5209
Reputation: 6853
I checked the differences between in API requests between the kubectl get pods
and kubectl -o custom columns
:
curl -k -v -XGET -H Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json -H User-Agent: kubectl/v1.18.8 (linux/amd64) kubernetes/9f2892a http://127.0.0.1:8001/api/v1/namespaces/default/pods?limit=500
curl -k -v -XGET -H Accept:
application/json -H User-Agent: kubectl/v1.18.8 (linux/amd64) kubernetes/9f2892a http://127.0.0.1:8001/api/v1/namespaces/default/pods?limit=500
So you will notice that when -o custom columns
is used, kubectl gets PodList
instead of Table
in response body. Podlist does not have that aggregated data, so to my understanding it is not possible to get the same output with kubectl pods using custom-column
.
Here's a code snippet responsible for the output that you desire. Possible solution would be to fork the client and customize it to your own needs since as you already might notice this output requires some custom logic. Another possible solution would be to use one of the Kubernetes api client libraries. Lastly you may want to try extend kubectl functionalities with kubectl plugins.
Upvotes: 5