⎈ k8s knowledge compiler

Field Selectors [page]deterministic

concepts

_Field selectors_ let you select Kubernetes [objects](#gloss:object) based on the value of one or more resource fields. Here are some examples of field selector queries:

* `metadata.name=my-service` * `metadata.namespace!=default` * `status.phase=Pending`

This `kubectl` command selects all Pods for which the value of the [`status.phase`](/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase) field is `Running`:

```shell kubectl get pods --field-selector status.phase=Running ```

> Note: Field selectors are essentially resource *filters*. By default, no selectors/filters are applied, meaning that all resources of the specified type are selected. This makes the `kubectl` queries `kubectl get pods` and `kubectl get pods --field-selector ""` equivalent.

## Supported fields

Supported field selectors vary by Kubernetes resource type. All resource types support the `metadata.name` and `metadata.namespace` fields. Using unsupported field selectors produces an error. For example:

```shell kubectl get ingress --field-selector foo.bar=baz ``` ``` Error from server (BadRequest): Unable to find "ingresses" that match label selector "", field selector "foo.bar=baz": "foo.bar" is not a known field selector: only "metadata.name", "metadata.namespace" ```

### List of supported fields

| Kind | Fields | | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Pod | `spec.nodeName`<br>`spec.restartPolicy`<br>`spec.schedulerName`<br>`spec.serviceAccountName`<br>`spec.hostNetwork`<br>`status.phase`<br>`status.podIP`<br>`status.podIPs`<br>`status.nominatedNodeName` | | Event | `involvedObject.kind`<br>`involvedObject.namespace`<br>`involvedObject.name`<br>`involvedObject.uid`<br>`involvedObject.apiVersion`<br>`involvedObject.resourceVersion`<br>`involvedObject.fieldPath`<br>`reason`<br>`reportingComponent`<br>`source`<br>`type` | | Secret | `type` | | Service | `spec.clusterIP`<br>`spec.type` | | Namespace | `status.phase` | | ReplicaSet | `status.replicas` | | ReplicationController | `status.replicas` | | Job | `status.successful` …(trimmed)

Sources

concepts/overview/working-with-objects/field-selectors.md · docField Selectors

Related (8)

references Objectobjects conf=1
references CustomResourceDefinitionCustomResourceDefinition conf=1
part_of Supported fieldsdescribes conf=1
part_of Supported operatorsdescribes conf=1
part_of Chained selectorsdescribes conf=1
part_of Multiple resource typesdescribes conf=1
part_of List of supported fieldsdescribes conf=1
part_of Custom resources fieldsdescribes conf=1

← all Docs