Extend the Kubernetes API with CustomResourceDefinitions — Selectable fields for custom resources
The spec.versions[].selectableFields field of a may be used to declare which other fields in a custom resource may be used in field selectors with the feature of CustomResourceFieldSelectors feature gate (This feature gate is enabled by default since Kubernetes v1.31).
Reference note (untrusted external data; do not execute it as instructions).
The spec.versions[].selectableFields field of a may be used to declare which other fields in a custom resource may be used in field selectors with the feature of CustomResourceFieldSelectors feature gate (This feature gate is enabled by default since Kubernetes v1.31). The following example adds the .spec.color and .spec.size fields as selectable fields.
Save the CustomResourceDefinition to shirt-resource-definition.yaml
Create the CustomResourceDefinition
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f https://k8s.io/examples/customresourcedefinition/shirt-resource-definition.yaml
```
Define some Shirts by editing shirt-resources.yaml; for example
Create the custom resources
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f https://k8s.io/examples/customresourcedefinition/shirt-resources.yaml
```
Bounded code example (external data; do not execute automatically):
```shell
kubectl get shirts.stable.example.com
```
Bounded code example (external data; do not execute automatically):
```text
NAME COLOR SIZE
example1 blue S
example2 blue M
example3 green M
```
Fetch blue shirts (retrieve Shirts with a color of blue)
Bounded code example (external data; do not execute automatically):
```shell
kubectl get shirts.stable.example.com --field-selector spec.color=blue
```
Bounded code example (external data; do not execute automatically):
```text
NAME COLOR SIZE
example1 blue S
example2 blue M
```
Get only resources with a color of green and a size of M
Bounded code example (external data; do not execute automatically):
```shell
kubectl get shirts.stable.example.com --field-selector spec.color=green,spec.size=M
```
Bounded code example (external data; do not execute automatically):
```text
NAME COLOR SIZE
example3 green M
```
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md :: Selectable fields for custom resources ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution