Model Deployment and Horizontal Pod Autoscaler
Below is a sample deployment YAML that runs a Flask application and its associated pod specification:While the load test executes in the background, observe how the Horizontal Pod Autoscaler automatically scales your application when the average CPU utilization exceeds 70%. You can inspect the HPA status with:Note that HPA uses the CPU resource requests defined in the deployment rather than the resource limits.
Using Node Affinity and Node Selectors
To ensure that specific pods run on nodes with specialized capabilities (for example, GPU-enabled nodes), you can use node affinity or node selectors.Node Affinity
Node affinity offers flexible scheduling policies based on node labels. To schedule pods exclusively on a node labeled “node02”, add the following affinity rules to your deployment:Node Selector
For a simpler scheduling approach, a node selector directly matches key-value pairs. The snippet below schedules the pod only on the node with the hostname “node02”:kubectl get nodes and kubectl describe node02, you’ll see that all model deployment pods are scheduled on node02, thereby keeping other nodes like node01 available for different workloads.
Taints and Tolerations
Taints allow nodes to repel certain pods unless they have the requisite tolerations. This is particularly useful for reserving nodes for specialized pods. For instance, taint node02 so that only pods with the corresponding toleration for key “role” and value “pytorch” are allowed to schedule:The absence of the required toleration in the Nginx deployment prevents its pods from landing on node02.
Requesting GPUs in Your Deployment
If your application benefits from GPU acceleration, ensure that your GPU-enabled nodes have NVIDIA drivers installed. Also, verify that your Docker image includes the necessary libraries and that the NVIDIA device plugin is deployed to your cluster. Update your container resource requests to include GPUs as shown below:Summary
In this article, we explored a range of advanced deployment scenarios in Kubernetes:- Deploying model applications using Deployment objects and Horizontal Pod Autoscalers.
- Leveraging node affinity and node selectors to target specific nodes.
- Applying taints and tolerations to reserve nodes for specialized workloads.
- Requesting GPUs in your container resource specifications.