kubectl get has an option
--field-selector, which is a selector (field query) to filter on the query results by key value pairs. But it’s very limited. As it’s mentioned in the help info: the server only supports a limited number of field queries per type. Normally, it only supports metadata.name, metadata.namespace, etc.
I’d like to know why it’s so limited. As an example, here I run a query to get deployment using metadata.name, and it works:
kubectl get deployment --field-selector metadata.name=echo NAME READY UP-TO-DATE AVAILABLE AGE echo 1/1 1 1 302d
However, if I want to add the status.readyReplicas filter, it won’t work and an error message is returned:
kubectl get deployment --field-selector metadata.name=echo,status.readyReplicas=1 Error from server (BadRequest): Unable to find "extensions/v1beta1, Resource=deployments" that match label selector "", field selector "metadata.name=echo,status.readyReplicas=1": "status.readyReplicas" is not a known field selector: only "metadata.name", "metadata.namespace"
As a workaround, I run the kubectl get w/ custom columns including the status.readyReplicas, then filter out at client side. But intuitively it would be more efficiently to handle it at server side.
Any idea on why, and, whether it makes sense to improve it.