Complete the code to specify pod affinity for pods with label app=frontend.
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- [1]
topologyKey: kubernetes.io/hostnameThe pod affinity requires pods with label app=frontend, so the value must be frontend.
Complete the code to specify pod anti-affinity to avoid scheduling pods on the same node with label app=database.
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: [1]
topologyKey: kubernetes.io/hostnamePod anti-affinity avoids scheduling pods on nodes with pods labeled app=database, so the value must be database.
Fix the error in the pod affinity configuration by completing the missing operator.
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: role
operator: [1]
values:
- frontend
topologyKey: failure-domain.beta.kubernetes.io/zoneExists or DoesNotExist when values are specified.NotIn which negates the match.The operator In is used to match pods whose label role is in the specified values list.
Fill both blanks to create a pod anti-affinity rule that avoids pods with label tier=backend on the same node.
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: tier
operator: [1]
values:
- [2]
topologyKey: kubernetes.io/hostnameNotIn which would invert the match.The operator In is used with the value backend to specify pods with label tier=backend for anti-affinity.
Fill all three blanks to define pod affinity that prefers pods with label env=prod and role=frontend on the same zone.
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 50
podAffinityTerm:
labelSelector:
matchExpressions:
- key: env
operator: [1]
values:
- [2]
- key: role
operator: [3]
values:
- frontend
topologyKey: failure-domain.beta.kubernetes.io/zoneNotIn which would exclude the desired pods.Both operators are In to match the values prod for env and frontend for role.