0
0
Kubernetesdevops~10 mins

Node affinity and anti-affinity in Kubernetes - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify node affinity that requires pods to run on nodes with the label 'disktype: ssd'.

Kubernetes
nodeAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchExpressions:
      - key: "disktype"
        operator: [1]
        values:
        - "ssd"
Drag options to blanks, or click blank then click option'
AExists
BNotIn
CIn
DDoesNotExist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Exists' which only checks if the label key exists, not its value.
Using 'NotIn' which excludes nodes with the value 'ssd'.
2fill in blank
medium

Complete the code to specify node anti-affinity that avoids scheduling pods on nodes with label 'zone: us-east-1a'.

Kubernetes
podAntiAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
  - labelSelector:
      matchExpressions:
      - key: "zone"
        operator: [1]
        values:
        - "us-east-1a"
    topologyKey: "kubernetes.io/hostname"
Drag options to blanks, or click blank then click option'
AExists
BNotIn
CDoesNotExist
DIn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NotIn' which would select pods not in the zone, thus not avoiding the zone.
Using 'Exists' which ignores the value and matches any pod with the label.
3fill in blank
hard

Fix the error in the node affinity expression to correctly require nodes with label 'env: production'.

Kubernetes
nodeAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchExpressions:
      - key: "env"
        operator: [1]
        values:
        - "production"
Drag options to blanks, or click blank then click option'
AIn
BNotIn
CExists
DDoesNotExist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NotIn' which excludes nodes with 'production' label.
Using 'Exists' which ignores the label value.
4fill in blank
hard

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.

Kubernetes
podAntiAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
  - labelSelector:
      matchExpressions:
      - key: [1]
        operator: [2]
        values:
        - "frontend"
    topologyKey: "failure-domain.beta.kubernetes.io/zone"
Drag options to blanks, or click blank then click option'
Aapp
BIn
Cenv
DNotIn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'env' as key which does not match the label.
Using 'NotIn' which selects pods without 'frontend' label.
5fill in blank
hard

Fill all three blanks to define a node affinity that prefers nodes with label 'region: us-west' and requires nodes with label 'ssd: true'.

Kubernetes
nodeAffinity:
  preferredDuringSchedulingIgnoredDuringExecution:
  - weight: 1
    preference:
      matchExpressions:
      - key: [1]
        operator: [2]
        values:
        - "us-west"
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchExpressions:
      - key: [3]
        operator: In
        values:
        - "true"
Drag options to blanks, or click blank then click option'
Aregion
BIn
Cssd
DExists
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys 'region' and 'ssd'.
Using 'Exists' operator which ignores label values.