2

Which fields can you use with Kubernetes field selectors?

 2 years ago
source link: https://hoelz.ro/blog/which-fields-can-you-use-with-kubernetes-field-selectors
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.signerNameCronJobstatus.successfulEventinvolvedObject.kindinvolvedObject.namespaceinvolvedObject.nameinvolvedObject.uidinvolvedObject.apiVersioninvolvedObject.resourceVersioninvolvedObject.fieldPathreasonsource (appears to resolve to metadata.source.component, falls back to reportingComponent)typereportingComponentJobstatus.successfulJobTemplatestatus.successfulNamespacestatus.phaseNodespec.unschedulablePodspec.nodeNamespec.restartPolicyspec.schedulerNamespec.serviceAccountNamestatus.phasestatus.podIPstatus.nominatedNodeNameReplicationControllerstatus.replicasSecretstatus.phasetypeStatefulSetstatus.successful

Published on 2022-01-24


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK