So I have 4 nodes. 1 is System, 1 is Dev, 1 is Qa and 1 is UAT.
My affinity is as follows:
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth
namespace: dev
labels:
app: auth
environment: dev
app-role: api
tier: backend
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
environment: dev
app-role: api
tier: backend
annotations:
build: _{Tag}_
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- auth
topologyKey: kubernetes.io/hostname
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: environment
operator: In
values:
- dev
containers:
- name: companyauth
image: company.azurecr.io/auth:_{Tag}_
imagePullPolicy: Always
env:
- name: ConnectionStrings__DevAuth
value: dev
ports:
- containerPort: 80
imagePullSecrets:
- name: ips
It is my intention to make sure that on my production cluster, which has 3 nodes in 3 different availability zones. That all the pods will be scheduled on a different node/availability zone. However, it appears that if I already have pods scheduled on a node, then when I do a deployment it will not overwrite the pods that already exist.
0/4 nodes are available: 1 node(s) didn't match pod affinity/anti-affinity, 3 node(s) didn't match node selector.
However, if I remove the podAffinity, it works fine and will overwrite the current node with the new pod from the deployment. What is the correct way to do this to ensure my deployment on my production cluster will always have a pod scheduled on a different node in a different availability zone and also be able to update the existing nodes?