Complete the code to specify node affinity that requires pods to run on nodes with the label 'disktype: ssd'.
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "disktype"
operator: [1]
values:
- "ssd"The operator In is used to specify that the node label 'disktype' must have the value 'ssd' for the pod to be scheduled on that node.
Complete the code to specify node anti-affinity that avoids scheduling pods on nodes with label 'zone: us-east-1a'.
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "zone"
operator: [1]
values:
- "us-east-1a"
topologyKey: "kubernetes.io/hostname"The operator In is used here to select pods running on nodes with label 'zone: us-east-1a' to avoid scheduling new pods on the same nodes.
Fix the error in the node affinity expression to correctly require nodes with label 'env: production'.
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "env"
operator: [1]
values:
- "production"The correct operator to require nodes with label 'env' equal to 'production' is In.
Fill both blanks to create a pod anti-affinity rule that avoids scheduling pods on nodes with pods labeled 'app: frontend' in the same zone.
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: [1]
operator: [2]
values:
- "frontend"
topologyKey: "failure-domain.beta.kubernetes.io/zone"The key is 'app' to match pods labeled 'app: frontend'. The operator 'In' selects pods with that label value to avoid colocating.
Fill all three blanks to define a node affinity that prefers nodes with label 'region: us-west' and requires nodes with label 'ssd: true'.
nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 preference: matchExpressions: - key: [1] operator: [2] values: - "us-west" requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: [3] operator: In values: - "true"
The preferred affinity uses key 'region' with operator 'In' to prefer nodes in 'us-west'. The required affinity uses key 'ssd' with operator 'In' to require nodes labeled 'ssd: true'.