k8s scheduling
getting deeper into k8s scheduling
25.11.2026
Things I worked on today and their notes
PriorityClass in k8s
- some pods are more important than others
- they are non-namespaced objects
- they are defined using a range of numbers for apps
- there is also another range for system (which has the highest priority)
$ k get priorityclasses.scheduling.k8s.io
NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY
system-cluster-critical 2000000000 false 19h PreemptLowerPriority
system-node-critical 2000001000 false 19h PreemptLowerPriority
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority # <- use this name in pod definition
value: 1000000
globalDefault: false
description: "This priority class should be used for XYZ service pods only." # <- optional
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
priorityClassName: high-priority # <- nice
If globalDefault is set to true, that PC is applied to all pods unless a pod specifies a different PC.
Let’s say we have two workloads:
- workload A with PC of 9
- workload B with PC of 7
We deploy these two and there are no resources left on the nodes anymore.
Now we have another workload C with PC of 8. What should happen here?
By default the lower PC (workload B) will be evicted and workload C will be placed instead.
If you don’t want this behaviour you have to define it in the PC manifest:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority-nonpreempting
value: 1000000
preemptionPolicy: Never # <- here
globalDefault: false
description: "This priority class will not cause other pods to be preempted."
Solved two labs:
✅KodeKloud - lab - priorityClasses
controlplane ~ ➜ k get priorityclasses.scheduling.k8s.io
NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY
system-cluster-critical 2000000000 false 6m45s PreemptLowerPriority
system-node-critical 2000001000 false 6m45s PreemptLowerPriority
Let’s call system-cluster-critical and system-node-critical greedy. If there are not enough resources for them, the scheduler will evict other pods 💀
✅Iximiuz - Kubernetes QoS Classes and Resource Management
The hardest part of the challenge was writing the jsonpath 😂 (which AI did; I won’t remember this)
jsonpath='{range .items[?(@.status.qosClass=="BestEffort")]}{.metadata.name}{"\n"}{end}'
You can have multiple schedulers in k8s, and in that case there has to be a leader election mechanism between them (distributed systems 101). Learn more in the configure multiple schedulers docs
Admission Controller
The docs are amazing, but here is the simple idea behind it.
After authentication and authorization, you want extra checks in place to stop people who are using the cluster from creating a manifest like this:
apiVersion: v1
kind: Pod
metadata:
name: web-pod
spec:
containers:
- name: ubuntu
image: ubuntu:latest
command: ["sleep", "3600"]
securityContext:
runAsUser: 0
capabilities:
add: ["MAC_ADMIN"]
If you want to see which admission controllers are enabled, use
❯ ps aux | grep kube-apiserver | grep enable
Or just open the kube-apiserver manifest and find the flag.
We have two types of admission controllers:
- Validating admission controllers (like
NamespaceExists) - Mutating admission controllers (like
DefaultStorageClass)
If you want to add your own admission controller, use:
MutatingAdmissionWebhookValidatingAdmissionWebhook
First mutation happens, then validation (I keep forgetting this)
Going back to Iximiuz to solve more k8s challenges
✅Iximiuz - Copy Files To/From a Running Kubernetes Pod: a Simple Case
Good one, but it doesn’t work if the file belongs to the root user (unless you use vi)
✅Iximiuz - Edit a File in a Running Kubernetes Pod: a Non-Root Container Case
This builds on the last challenge, but this time we can’t just run k cp anymore b/c of file permissions.
This is where k debug comes into play, aka using an ephemeral container.
The idea is to create an ephemeral container in the pod (in this case web-server) that shares the PID namespace of the target container (in this case app).
Really elegant way of debugging.
There was also a second solution: using cdebug