$ kubectl get pods -o json
$ kubectl get pods -o jsonpath='{@}'
$ kubectl get pods -o jsonpath='{.items[0]}'
$ kubectl get pods -o jsonpath='{.items[0].metadata.name}'
$ kubectl get pods -o jsonpath="{.items[*]['metadata.name', 'status.capacity']}"
$ kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.startTime}{"\n"}{end}'
$ kubectl get pods -o jsonpath='{.items[*].status.podIP}'
$ kubectl get pods -o jsonpath='{range .items[*]}{.status.podIP}{"\n"}{end}'
$ kubectl get pods -o jsonpath='{range .items[*].spec.containers[*]}{.image}{"\n"}{end}' -A
$ oc get kubeapiserver cluster -o=jsonpath='{range .status.conditions[?(@.type=="NodeInstallerProgressing")]}{.reason}{"\n"}{.message}{"\n"}{end}'
kubectl does not support regular expressions for JSONpath output. The following command does NOT work:
$ kubectl get pods -o jsonpath='{.items[?(@.metadata.name=~/^test$/)].metadata.name}'
The following command achieves the desired result:
$ kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test("test-")).spec.containers[].image'
The
{end}
is missing here.