Affinity
Node affinity is a Kubernetes scheduling constraint that requires or prefers placing a pod on nodes whose labels match specified expressions.
Google Anthos in Action
Node affinity is a Kubernetes scheduling constraint that selects nodes through label expressions and required or preferred matching behavior.
- How it is used
- Constrains Kubernetes Pod placement to nodes whose labels meet workload requirements, including specialized-hardware or location needs.
- How deep it goes
- Works through label expressions and a required node-affinity Pod manifest, while leaving custom scheduler implementation outside its scope.
- Examples
- Shows a Pod restricted to two zones through an In expression and supplies kubectl commands for checking node labels and Pod placement.
- What you can do after
- Apply it via Kubernetes Pod manifests to constrain eligible nodes with label expressions and inspect placement with kubectl.
Kubernetes in Action, Second Edition
Node affinity is a Kubernetes pod-scheduling rule that constrains placement to nodes matching specified node attributes.
- How it is used
- Constrains Pod placement to nodes selected by labels or fields, including rules that exclude nodes.
- How deep it goes
- Works through required affinity terms, expression matching, supported operators, and a field-based variant; does not detail scheduler internals.
- Examples
- Shows a Pod requiring a front-end label without a skip-me label, a Pending result, and a rule excluding a named node.
- What you can do after
- Operate/configure it in Pod manifests to require or exclude nodes, then check placement or Pending status with kubectl.
Read how Kubernetes in Action, Second Edition explains affinity →
Acing the Certified Kubernetes Administrator Exam, Second Edition
Node affinity is a Kubernetes scheduling technique that expresses preferences or requirements for placing pods on nodes.
- How it is used
- Controls pod placement when node labels should express hard requirements or flexible preferences.
- How deep it goes
- Explains hard and soft rules, weights, YAML placement, and verification, but does not provide the complete affinity manifest.
- Examples
- Uses an nginx pod manifest, affinity.yaml, kubectl apply, and kubectl get po -o wide output.
- What you can do after
- Operate/configure pod placement with node labels, affinity YAML, kubectl, and observable scheduling results.
Read how Acing the Certified Kubernetes Administrator Exam, Second Edition explains affinity →
Effective Platform Engineering
Node affinity is a Kubernetes scheduling constraint that attracts pods to nodes matching specified labels.
- How it is used
- Directs Kubernetes pods toward labeled nodes when testing storage workloads on Karpenter-managed EKS clusters.
- How deep it goes
- Defines label-based placement and shows a required scheduling manifest, but does not detail scheduler internals.
- Examples
- Uses a management-node storage pod that mounts EBS-backed storage and is checked with kubectl and Bats.
- What you can do after
- Configure pod placement with label selectors and verify scheduling and mounted-volume writes through Kubernetes tests.
Kubernetes for Developers
Node affinity is a Kubernetes scheduling constraint that requires or prefers placing a Pod on nodes whose labels match specified expressions.
- How it is used
- Places workloads on nodes with required or preferred hardware, operating-system, architecture, or provisioning characteristics.
- How deep it goes
- Defines labels, operators, required rules, preferred rules, verification, and autoscaling caveats without detailing scheduler internals.
- Examples
- Uses Arm-only placement, mixed Arm-or-x86 requirements, preferred Arm placement, and command-line node inspection.
- What you can do after
- Apply node affinity in a PodSpec and verify that Kubernetes schedules the Pod onto matching labeled nodes.
Machine Learning Platform Engineering
A Kubernetes affinity configuration expresses scheduling preferences or requirements that influence which nodes may run a pod.
- How it is used
- Directs Kubeflow notebook pods toward suitable cluster nodes, including GPU hosts and CPU tiers.
- How deep it goes
- Shows production configuration through labels, selector terms, UI defaults, and taint interactions, but does not detail scheduler internals.
- Examples
- Uses small-cpu and xl-cpu selectors, compute labels, GPU-capable nodes, and a Kubeflow node-affinity ConfigMap.
- What you can do after
- Operate/configure Kubeflow notebook placement through labeled-node affinity choices and coordinated taints and tolerations.
Read how Machine Learning Platform Engineering explains affinity →
Related concepts
- node selectorcontrasts with · A node selector is a Kubernetes scheduling constraint that restricts a pod or workload to nodes having specified matching labels.
- anti-affinitycontrasts with · Anti-affinity is a scheduling constraint that discourages or prevents selected workloads from sharing a node or topology domain with matching workloads.
- Kubernetes scheduleruses · The Kubernetes scheduler is a control-plane component that assigns unscheduled Pods to suitable nodes according to resource requirements and scheduling constraints.
- Kubernetesused by · Kubernetes is an open-source platform for orchestrating and automating the deployment, scaling, and management of containerized workloads across computing clusters.
- podconfigures · A Kubernetes Pod is the smallest deployable unit in Kubernetes, grouping one or more co-located containers that share networking and other resources.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.





