liveBook · Manning

Field selector

As explained in Kubernetes in Action, Second Edition

A field selector is a Kubernetes API query mechanism that filters objects by matching specified field values.

A field selector filters Kubernetes API objects by matching specified field values. It helps narrow kubectl results to objects with a particular property, such as Warning events or pods assigned to one node. section 4.3.1 section 7.4

Use field selectors with kubectl to find specific objects:

  • List warning events with kubectl get ev --field-selector type=Warning. section 4.3.1
  • List pods scheduled on a node with kubectl get pods --field-selector spec.nodeName=kind-worker. section 7.4.1
  • Find pods that are not running with kubectl get pods --field-selector status.phase!=Running; add -A to search all namespaces. section 7.4.1

Supported fields depend on the object kind. metadata.name and metadata.namespace are always supported. Use kubectl explain to inspect object fields, then verify whether a chosen field is supported in selectors. section 7.4 section 7.4.1

$ kubectl get pods --field-selector spec.nodeName=kind-worker
NAME               READY   STATUS    RESTARTS   AGE
kiada-front-end    2/2     Running   0          15m
kiada-002          2/2     Running   0          3h
quote-002          2/2     Running   0          3h

Shows the command output for selecting pods assigned to a specific node. section 7.4.1

$ kubectl get pods --field-selector status.phase!=Running
NAME                       READY   STATUS    RESTARTS   AGE
kiada-front-end-affinity   0/2     Pending   0          41m

Shows the command output for selecting pods whose phase is not Running. section 7.4.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains matching, supported fields, inequality, namespace scope, and verification, but does not detail selector implementation internals.
Examples
Demonstrates warning events, node-assigned pods, and pods whose status phase differs from Running.
What it assumes
Assumes basic kubectl and Kubernetes object familiarity while teaching field matching and selector-field discovery.
What you can do after
Apply field selectors through kubectl to locate warnings, node-specific pods, and nonrunning pods.
How it connects
Connects Kubernetes API objects, kubectl, pods, events, namespaces, label selectors, and kubectl explain.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.