Module 10: Kubernetes Resource Management & Scheduling

DevOpsLaunchpadDevOpsLaunchpad
3 min read

Managing workloads in Kubernetes is not just about deploying applications – it’s about making sure your cluster resources (CPU, memory, nodes) are used efficiently and fairly. In this module, we’ll explore how Kubernetes schedules pods and how you can control resource usage using powerful features like Requests, Limits, QoS, Taints, Tolerations, and more.


πŸ”Ή 1. Why Resource Management Matters

Without proper resource management:

  • One pod can consume all CPU/memory and starve others.

  • Critical workloads may get evicted when nodes run out of memory.

  • Apps may get scheduled on the wrong nodes.

Kubernetes provides fine-grained controls to handle this.


πŸ”Ή 2. Resource Requests & Limits

Every container can specify:

  • Requests β†’ minimum CPU/memory it needs.

  • Limits β†’ maximum CPU/memory it can use.

πŸ“Œ YAML Example:

apiVersion: v1
kind: Pod
metadata:
  name: resource-demo
spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      requests:
        memory: "128Mi"
        cpu: "250m"
      limits:
        memory: "256Mi"
        cpu: "500m"

βœ… Kubernetes scheduler uses requests to decide where to place the pod. βœ… Limits protect nodes by capping resource consumption.


πŸ”Ή 3. Quality of Service (QoS) Classes

Kubernetes assigns each pod a QoS class automatically:

  1. Guaranteed – Requests == Limits for all containers.

  2. Burstable – Requests < Limits.

  3. BestEffort – No requests/limits set.

πŸ’‘ Eviction priority β†’ Guaranteed > Burstable > BestEffort.


πŸ”Ή 4. Taints & Tolerations

Taints let you repel pods from specific nodes, unless they tolerate it.

πŸ“Œ Example: Taint a node

kubectl taint nodes node1 dedicated=database:NoSchedule

πŸ“Œ Pod with toleration

tolerations:
- key: "dedicated"
  operator: "Equal"
  value: "database"
  effect: "NoSchedule"

βœ… Ensures only database pods run on that node.


πŸ”Ή 5. Node Affinity & Anti-Affinity

Control where pods get scheduled:

  • Affinity β†’ attract pods to nodes with certain labels.

  • Anti-Affinity β†’ spread pods across nodes.

πŸ“Œ Example: Schedule pod only on nodes labeled zone=us-east1

affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: zone
          operator: In
          values:
          - us-east1

πŸ”Ή 6. Pod Priority & Preemption

When resources are scarce:

  • Higher priority pods can evict lower priority ones.

πŸ“Œ PriorityClass Example

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: high-priority
value: 1000
globalDefault: false
description: "High priority for critical workloads"

πŸ“Œ Pod with priority

spec:
  priorityClassName: high-priority

βœ… Critical apps always win scheduling battles.


πŸ”Ή 7. Hands-On Checklist

Run these in your cluster:

  1. Deploy a pod with requests & limits.

  2. Check QoS class β†’ kubectl describe pod resource-demo.

  3. Add a taint to a node & deploy a pod with toleration.

  4. Test node affinity by labeling nodes.

  5. Create a high-priority pod & watch it preempt others.


πŸ”Ή 8. Kubernetes Resource Scheduling – Visual Diagram

Here’s a simple architecture to visualize resource scheduling:

Here’s the colorful diagram showing Nodes (with taints/labels), Pods (with affinity/tolerations), and Scheduler decisions. πŸš€


βœ… Conclusion

Resource management ensures that your apps:

  • Run reliably without resource starvation.

  • Get placed on the right nodes.

  • Scale efficiently in shared clusters.

With Requests, Limits, QoS, Taints, Affinity, and Priority, you gain full control over scheduling and prevent cluster chaos. πŸš€


0
Subscribe to my newsletter

Read articles from DevOpsLaunchpad directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

DevOpsLaunchpad
DevOpsLaunchpad