Middle+
What rule will you use to ensure the operation of the necessary pods on specific nodes, for example, on workers for GPU and ML computations: taint, pod affinity, or something else?
sobes.tech AI
Answer from AI
To ensure the operation of pods with GPU/ML workloads on specific nodes (for example, GPU nodes), I would combine Taints and Tolerations with Node Affinity.
Taints and Tolerations:
- Taint: I would "mark" GPU nodes with a specific Taint, for example,
gpu=true:NoSchedule. This guarantees that pods which do not tolerate this Taint will not be scheduled on these nodes. - Toleration: Pods requiring GPU/ML resources will have a corresponding Toleration for
gpu=true. This allows them to be scheduled on nodes with this Taint.
# Example of a pod specification with Toleration
apiVersion: v1
kind: Pod
metadata:
name: ml-gpu-pod
spec:
containers:
- name: ml-container
image: your-ml-image
resources:
limits:
nvidia.com/gpu: 1 # Request GPU
tolerations:
- key: "gpu"
operator: "Equal"
value: "true"
effect: "NoSchedule"
Node Affinity:
In combination with Taints, I would use Node Affinity for active preference (or requirement) to schedule GPU pods on GPU nodes.
- requiredDuringSchedulingIgnoredDuringExecution: If it is critical that the pod always runs on a GPU node.
- preferredDuringSchedulingIgnoredDuringExecution: If it is desirable but not strictly necessary to run the pod on a GPU node.
# Example of a pod specification with Node Affinity
apiVersion: v1
kind: Pod
metadata:
name: ml-gpu-pod
spec:
containers:
- name: ml-container
image: your-ml-image
resources:
limits:
nvidia.com/gpu: 1
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution: # Or preferred...
nodeSelectorTerms:
- matchExpressions:
- key: gpu # Example label on GPU node
operator: In
values:
- "true"
tolerations:
- key: "gpu"
operator: "Equal"
value: "true"
effect: "NoSchedule"
Explanation of the choice:
- Taints and Tolerations prevent "incorrect" pods from landing on GPU nodes, conserving resources.
- Node Affinity ensures that GPU pods actively seek and are scheduled on GPU nodes.
- Pod Affinity/Anti-Affinity are less directly applicable for node type selection. They are more used for placing pods relative to other pods.
Thus, the combination of Taints and Node Affinity provides both exclusion (Taints) of undesired pods from GPU nodes and attraction (Node Affinity) of desired pods to them.