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
PodAntiAffinitycan be configured to ensure that the scheduler does not co-locate replicas on a single node.Below mentioned is the snippet of
PodAntiAffinityconfigured 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/hostnameThis configuration makes sure that all 3 replicas of the pods are scheduled on three different nodes of the cluster.
Additional Information
PreviousHow To Customize CoreDNS Configuration for Adding Additional External DNS
NextHow To Rotate Container Logs on The Master and Worker Nodes
Last updated
