How to use Kubernetes fieldSelector to query ownerReferences
The --field-selector
only works with some limited fields.
Which contains:
"metadata.name","metadata.namespace","spec.nodeName","spec.restartPolicy","spec.schedulerName","spec.serviceAccountName","status.phase","status.podIP","status.podIPs","status.nominatedNodeName"
But you can perform the task by using jq
. Here is a command that I used for listing all ready nodes. It demonstrates the use of array fields that you're looking for.
$ kubectl get nodes -o json | jq -r '.items[] | select(.status.conditions[] | select(.type=="Ready" and .status=="True")) | .metadata.name 'master-0node-1node-3
I think what you really want to do is a filter rather than a query. By using JSONPath you can filter out content using ?()
.
For example the following would work:
kubectl get pods -o jsonpath='{range .items[?(.metadata.ownerReferences.uid=262bab1a-1c79-11ea-8e23-42010a800016)]}{.metadata.name}{end}'