Kubernetes check

Multi-replica Deployment has no explicit replica spread rule

K8S-REL-005LowReliability

Trigger condition

A Deployment with a desired replica count of 2 or more has no applicable topologySpreadConstraints entry and no applicable Pod anti-affinity term (required or preferred) in its current Pod template. A rule is applicable only when it has a topology key, a selector that matches the Deployment's own current Pod template labels, and -- when matchLabelKeys or (for anti-affinity) mismatchLabelKeys is set -- those keys resolve favorably against the template; for anti-affinity, its namespace scope (namespaces and/or namespaceSelector) must also cover the Deployment's own namespace. A mismatchLabelKeys entry naming a key present on the template (e.g. tenant) excludes the Deployment's own same-tenant replicas by design, so that term never satisfies this check even though its static selector alone would otherwise match them. Both DoNotSchedule and ScheduleAnyway topology-spread rules count, and both required and preferred anti-affinity terms count. Evaluated from the current template alone, even when the Deployment has no live Pods at all. When a rule's applicability depends on a namespaceSelector, matchLabelKeys, or mismatchLabelKeys this project cannot resolve from the collected template (it does not collect namespace labels, and a key absent from the template may be a controller- or admission-added label it cannot see) and that rule would otherwise apply, the result is treated as indeterminate and no finding is produced, rather than guessing.

Evidence

States the Deployment's name and its desired replica count, and that no explicit topology spread or Pod anti-affinity rule applies to its current Pod template.

Impact

Without an applicable rule, the scheduler is free to place more than one of this Deployment's replicas on the same node, so losing that node can affect more than one replica at once. This finding concerns only this Deployment's own explicit rules: Kubernetes can still apply scheduler defaults, and this check does not establish where any live replica is actually placed.

Recommendation

Add a topologySpreadConstraint or podAntiAffinity rule with a selector scoped to this workload's own Pod template labels, using kubernetes.io/hostname as the topology key for node-level spread. A preference (ScheduleAnyway, or a preferred anti-affinity term) can still allow co-location when the scheduler decides it must. DoNotSchedule enforces the configured skew, but a hard spread constraint can still permit multiple replicas per node within that skew -- it does not guarantee exactly one replica per node. Both a hard spread constraint and a required anti-affinity term can leave Pods pending when eligible capacity is insufficient.

Important limitations

This check only evaluates whether some topologySpreadConstraints entry or Pod anti-affinity term applies to the Deployment's current template -- it never validates maxSkew, minDomains, node taint/affinity policy, or weight values, and it never establishes where any live replica is actually scheduled. It does not inspect node affinity/selector, PodDisruptionBudgets (K8S-REL-004), or an older ReplicaSet's own template. A non-trivial, unresolvable namespaceSelector, matchLabelKeys, or mismatchLabelKeys entry suppresses the finding rather than guessing, which can under-report in that specific, narrow case.

← Back to the check catalogue