Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

How To Avoid Placement of More Than One Pod Replicas on Same Worker Node

Problem

  • How to avoid assignment of multiple replicas of a pod on a single worker node?

  • How to configure deployment to avoid co-location of replicas on a single node?

Environment

  • Platform9 Managed Kubernetes - All Versions

  • Kube-Scheduler

Procedure

  • PodAntiAffinity can be configured to ensure that the scheduler does not co-locate replicas on a single node.

  • Below mentioned is the snippet of PodAntiAffinity configured for a Nginx deployment with 3 pod replicas.

# kubectl get deployment nginx-deployment -o yaml | grep -w "podAntiAffinity:" -A8
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx
            topologyKey: kubernetes.io/hostname
  • This configuration makes sure that all 3 replicas of the pods are scheduled on three different nodes of the cluster.

Additional Information

Last updated