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.
# kubectl get po -o wide -n default
NAME READY STATUS RESTARTS AGE IP NODE
nginx-deployment-84c6674589-cxp55 1/1 Running 0 55s 10.20.152.138 10.128.228.29
nginx-deployment-84c6674589-hzmnn 1/1 Running 0 55s 10.20.155.70 10.128.228.28
nginx-deployment-84c6674589-vq4l2 1/1 Running 0 55s 10.20.225.7 10.128.226.44
Additional Information
Was this page helpful?