Scheduling application replicas to different nodes (pod affinity)
Using nodeAffinity
does not ensure that pods will next time be scheduled onto separate nodes, and for real application high availability, the best practice is to ensure that application pods are scheduled onto separate nodes. If one of the nodes is down/rebooted/replaced, having all the pods running on that node will cause the application to go down and its services to be unavailable.
Let's update the deployment.yaml
file with the podAntiAffinity
rule so that the nginx
application is only scheduled to gke-kubectl-lab-we-app-pool
and onto separate nodes:
... spec: Â Â affinity: Â Â Â Â nodeAffinity: Â Â Â Â Â Â requiredDuringSchedulingIgnoredDuringExecution: Â Â Â Â Â Â Â Â nodeSelectorTerms: Â Â Â Â Â Â Â Â - matchExpressions: Â Â Â Â Â Â Â Â Â Â - key: node...