---
source: https://iinventedlight.com/library/notes/kubernetes-inter-pod-affinity.md
title: "Kubernetes inter-pod affinity constrains Pods using other Pod labels"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes); CC-BY-4.0 (kubernetes/website); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Kubernetes, Assigning Pods to Nodes; kubernetes/website, Assigning Pods to Nodes (Kubernetes website source). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Kubernetes inter-pod affinity"
tags: [kubernetes, affinity, scheduling, topologyKey, anti-affinity]
client: Librarian
sources:
  - id: S1
    title: "Assigning Pods to Nodes"
    publisher: Kubernetes
    url: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "Assigning Pods to Nodes (Kubernetes website source)"
    publisher: kubernetes/website
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/scheduling-eviction/assign-pod-node.md
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# Kubernetes inter-pod affinity constrains Pods using other Pod labels
**Answer:** Inter-pod affinity and anti-affinity allow you to constrain Pods against labels on other Pods. A topologyKey is the key for the node label that denotes the domain. This is separate from nodeSelector, which only selects nodes with all the specified labels, and from node affinity, which uses a more expressive syntax on node labels.

## Required and preferred rules

preferredDuringSchedulingIgnoredDuringExecution means the scheduler tries to find a node that meets the rule. A required rule must be met for the Pod to be scheduled. You can also specify node affinities using the .spec.affinity.nodeAffinity field in your Pod spec.

## Notes

Kubernetes also populates a standard set of labels on all nodes in a cluster. If you use labels for node isolation, choose label keys that the kubelet cannot modify.

## See also

- [kubernetes-node-affinity](https://iinventedlight.com/library/notes/kubernetes-node-affinity/)
- [kubernetes-taints-tolerations](https://iinventedlight.com/library/notes/kubernetes-taints-tolerations/)
- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)

## Claims

- id: C1
  claim: Inter-pod affinity and anti-affinity constrain Pods against labels on other Pods.
  source: S1
  evidence: "Inter-pod affinity/anti-affinity allows you to constrain Pods against labels on other Pods."

- id: C2
  claim: nodeSelector only selects nodes with all the specified labels.
  source: S1
  evidence: "nodeSelector only selects nodes with all the specified labels."

- id: C3
  claim: preferredDuringSchedulingIgnoredDuringExecution means the scheduler tries to find a node that meets the rule.
  source: S2
  evidence: "The scheduler tries to find a node that meets the rule."

- id: C4
  claim: Inter-pod affinity is set with the affinity.podAffinity field in the Pod spec.
  source: S2
  evidence: "To use inter-pod affinity, use the `affinity.podAffinity` field in the Pod spec."

## Sources

- [S1] Assigning Pods to Nodes. Kubernetes. https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ . License: CC-BY-4.0. Accessed 2026-11-23.

- [S2] Assigning Pods to Nodes (Kubernetes website source). kubernetes/website. https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/scheduling-eviction/assign-pod-node.md . License: CC-BY-4.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes, Assigning Pods to Nodes; kubernetes/website, Assigning Pods to Nodes (Kubernetes website source). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
