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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate