Hi I am trying to run kubectl -n*** get pods
this return the standard one and it includes names, ready, and status...
What I need is the name and ready However, I couldn't do this by using custom-column. Need helps on how I can add the ready column back to the custom-column
kubectl -n*** get pods -o=custom-columns="NAME:.metadata.name"
Thanks in advance
CodePudding user response:
kubectl get pods -o custom-columns='NAME:metadata.name,READY:status.conditions[?(@.type=="Ready")].status'
CodePudding user response:
Solution using go-template
:
kubectl get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready }}{{$element.metadata.name}} {{"READY\n"}}{{end}}{{end}}{{end}}'
Example:
k get pod
NAME READY STATUS RESTARTS AGE
httpd-757fb56c8d-2vnw4 1/1 Running 2 (6h24m ago) 3d3h
readiness-exec 0/1 Running 0 22s #<---this is not ready
nginx 1/1 Running 2 (6h24m ago) 4d1h
nginx-6799fc88d8-5cflk 1/1 Running 2 (6h24m ago) 3d3h
// non-ready(readiness-exec
) pod is not listed:
kubectl get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready }}{{$element.metadata.name}} {{"READY\n"}}{{end}}{{end}}{{end}}'
httpd-757fb56c8d-2vnw4 READY
nginx READY
nginx-6799fc88d8-5cflk READY
//once the readiness-exec
pod is ready:
kubectl get pods -o go-template='{{range $index, $element := .items}}{{range .status.containerStatuses}}{{if .ready }}{{$element.metadata.name}} {{"READY\n"}}{{end}}{{end}}{{end}}' |column -t
httpd-757fb56c8d-2vnw4 READY
readiness-exec READY
nginx READY
nginx-6799fc88d8-5cflk READY