Room 46
CUSTOM SCHEDULER
The Scheduler’s Throne
- The default scheduler places pods on nodes based on resource availability. But what if you need custom logic?
- Deploy a custom scheduler and configure pods to use it.
📜 Mission Briefing
- Study how the default scheduler works: predicates → priorities → binding.
- Deploy
custom-scheduler.yaml- a simple scheduler that runs as a pod. - Create a pod that uses
schedulerName: custom-scheduler. - Verify the pod is scheduled by the custom scheduler.
- Check the scheduler pod logs for the password:
schedlr7.
Key Commands
| Command | Purpose |
|---|---|
kubectl get pods -n kube-system -l component=kube-scheduler |
Default scheduler |
kubectl logs -n kube-system kube-scheduler-* |
Scheduler logs |
kubectl get events --field-selector reason=Scheduled |
Scheduling events |
How the Scheduler Works
# Scheduling Cycle:
# 1. Watch: New pod with no nodeName
# 2. Filter: Remove nodes that can't run the pod (predicates)
# - Insufficient resources
# - Node taints without tolerations
# - Node affinity mismatch
# 3. Score: Rank remaining nodes (priorities)
# - Spread pods across nodes
# - Prefer nodes with images cached
# - Resource utilization balance
# 4. Bind: Assign pod to highest-scoring node
# Scheduler extension points (framework):
# QueueSort → PreFilter → Filter → PostFilter →
# PreScore → Score → NormalizeScore →
# Reserve → Permit → PreBind → Bind → PostBind
# Pod using a custom scheduler
apiVersion: v1
kind: Pod
metadata:
name: custom-scheduled
spec:
schedulerName: custom-scheduler # Use custom scheduler
containers:
- name: app
image: nginx:alpine
# Simple custom scheduler deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: custom-scheduler
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
component: custom-scheduler
template:
metadata:
labels:
component: custom-scheduler
spec:
serviceAccountName: custom-scheduler
containers:
- name: scheduler
image: registry.k8s.io/kube-scheduler:v1.29.0
command:
- kube-scheduler
- --config=/etc/kubernetes/scheduler-config.yaml
volumeMounts:
- name: config
mountPath: /etc/kubernetes
volumes:
- name: config
configMap:
name: scheduler-config
# Multiple schedulers can coexist
# Each pod specifies which scheduler handles it
# Default scheduler: spec.schedulerName: default-scheduler (or omit)
# Scheduler profiles (K8s 1.18+):
# Configure multiple profiles in a single scheduler binary
# Each profile can enable/disable different plugins
Hints
Hint 3
The password is schedlr7.