Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a pod spec that pins pods to GPU nodes using node affinity and tolerations.

AdvancedHands-onWrite-a-Kubernetes-manifest tasks
Answer
spec:
  tolerations:
    - key: nvidia.com/gpu
      operator: Exists
      effect: NoSchedule
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: node.kubernetes.io/instance-type
                operator: In
                values: ["g5.xlarge", "g5.2xlarge"]
  containers:
    - name: trainer
      image: myrepo/trainer:1.0
      resources:
        limits: { nvidia.com/gpu: 1 }

Key trick → A taint keeps other pods off GPU nodes and the toleration allows these pods on, but only affinity forces them there. You need both halves. The GPU limit needs the NVIDIA device plugin.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks