Which fields can you use with Kubernetes field selectors?
Field selectors are a handy filter you can provide kubectl get
via the --field-selector
option to pare down the list of resources you get back from the server. The docs mention that supported fields vary from resource to resource, but sadly don't mention which resources support which fields. I did a little bit of poking around, and - as far as I can tell - this isn't documented anywhere! So, seeing as reading source code is one of my Maslow's hammers, I broke out that particular hammer and got to reading.
After a little bit of time and effort I managed to find the code that determines which fields are valid for field selectors - you can find it by looking for GetAttrs
in **/strategy.go
in the Kubernetes repository. So now once this post becomes outdated, you can refresh the list for yourself :)
Here's the list of which resources support which fields (in addition to metadata.namespace
and metadata.name
, which all resources support) as of Kubernetes 1.20:
CertificateSigningRequest | spec.signerName |
CronJob | status.successful |
Event | involvedObject.kind |
involvedObject.namespace | |
involvedObject.name | |
involvedObject.uid | |
involvedObject.apiVersion | |
involvedObject.resourceVersion | |
involvedObject.fieldPath | |
reason | |
source (appears to resolve to metadata.source.component, falls back to reportingComponent) | |
type | |
reportingComponent | |
Job | status.successful |
JobTemplate | status.successful |
Namespace | status.phase |
Node | spec.unschedulable |
Pod | spec.nodeName |
spec.restartPolicy | |
spec.schedulerName | |
spec.serviceAccountName | |
status.phase | |
status.podIP | |
status.nominatedNodeName | |
ReplicationController | status.replicas |
Secret | status.phase |
type | |
StatefulSet | status.successful |