1.

What is node affinity and pod affinity?

Answer»
  1. Node Affinity ensures that pods are hosted on particular nodes.

Pod Affinity ensures TWO pods to be co-located in a SINGLE node.

Node Affinity

apiVersion: v1 kind: Pod metadata: name: with-node-affinity spec: affinity: nodeAffinity:       requiredDuringSchedulingIgnoredDuringExecution:         nodeSelectorTerms:         - matchExpressions:           - key: Kubernetes.io/e2e-az-name             operator: In             values:             - e2e-az1

Pod Affinity

apiVersion: v1 kind: Pod metadata: name: with-pod-affinity spec:   affinity:     podAffinity:       requiredDuringSchedulingIgnoredDuringExecution:       - labelSelector:           matchExpressions:           - key: security             operator: In             values:             - S1

The pod affinity rule SAYS that the pod can be scheduled to a node only if that node is in the same zone as at least one already-running pod that has a label with key “security” and VALUE “S1”

Reference: https://Kubernetes.io/docs/concepts/configuration/assign-pod-node/



Discussion

No Comment Found

Related InterviewSolutions