In part 17 you told Pods where they want to run. This episode looks at it from the other side. A taint lets a node refuse Pods. A PriorityClass decides who wins when the cluster is full. A PodDisruptionBudget limits how many replicas planned maintenance may take down at once, and kubectl drain is the maintenance command that respects it. You need the three-worker kind cluster from part 17 and the k8s-from-zero namespace as your context namespace. We tested on kind v0.33.0 (node image v1.37.0) with kubectl v1.37.2.
What you will build
You will reserve one worker for “GPU” work with a taint and watch an ordinary Deployment avoid it while a tolerating Pod gets in. You will add a NoExecute taint and see one Pod leave at once and another leave after 20 seconds. Then you fill the cluster with low-priority Pods and start a high-priority one that preempts a victim. Last, you drain a node with a budget that blocks it, loosen the budget, and drain again.
Taints repel, tolerations permit
A taint is a key=value:effect set on a node. A toleration is a matching entry in a Pod’s spec. A Pod may run on a tainted node only if it tolerates every taint there. There are three effects:
NoSchedule: new Pods without a matching toleration are not scheduled there. Running Pods stay.PreferNoSchedule: the soft version. The scheduler tries to avoid the node.NoExecute: new Pods are kept off, and running Pods without a toleration are evicted. A toleration can settolerationSecondsto stay for a while before eviction.
A toleration matches when the key and effect match and either the values are equal (operator: Equal, the default) or the operator is Exists, which matches any value. A toleration gives permission and no direction: it lets a Pod onto the node and does nothing to pull it there. To reserve nodes for a team or for GPU work, combine a taint (keeps others off) with a node label and affinity (pulls the right Pods on).
You have met a taint already. The control plane node carries node-role.kubernetes.io/control-plane:NoSchedule, which is why your Pods never ran there. Kubernetes also adds taints when something goes wrong with a node, such as node.kubernetes.io/not-ready and node.kubernetes.io/unreachable. Every Pod gets default tolerations for those two with tolerationSeconds: 300, so when a node dies, its Pods are evicted and replaced elsewhere after about five minutes.
Priority decides who gets the last seat
When there is no room for a Pod, the scheduler can preempt: evict lower-priority Pods to make space. A Pod’s priority comes from a PriorityClass, a cluster-wide object with a value. Your classes can use any 32-bit integer up to 1 billion; higher means more important. Kubernetes ships two classes above that range, system-cluster-critical and system-node-critical, for parts of the cluster itself. A Pod without priorityClassName gets priority 0, unless one class has globalDefault: true.
Preemption has limits worth knowing:
- Victims get their normal graceful termination period, so the high-priority Pod waits for it.
- The scheduler tries to respect PodDisruptionBudgets when it picks victims, but only on a best-effort basis.
- A class with
preemptionPolicy: Neverputs its Pods ahead in the queue without evicting anybody. - Preemption only frees resources counted by requests. A node that looks busy but has low requests is not “full” to the scheduler (part 11).
Use few classes with clear meaning, such as “customer-facing,” “internal” and “batch.” Without limits, everyone marks their app as critical. An administrator can use ResourceQuota to stop users from creating Pods at high priorities.
Voluntary disruptions and PodDisruptionBudgets
The docs split disruptions in two. Involuntary ones are failures nobody chose: a node crashes, a disk dies, a cloud VM disappears. Voluntary ones are actions somebody takes on purpose: draining a node for an upgrade (part 33), scaling down the cluster (part 37), deleting a Pod by hand.
A PodDisruptionBudget (PDB) protects an app from too many voluntary disruptions at once. You select the app’s Pods with a label and set either minAvailable (how many must stay up) or maxUnavailable (how many may be down), as a number or a percentage. Tools that respect PDBs use the Eviction API instead of deleting Pods directly. If an eviction would break the budget, the API refuses it and the tool retries later. kubectl drain works this way. A plain kubectl delete pod does not check the budget at all.
A PDB never stops involuntary disruptions. If a node crashes, its Pods are gone no matter what the budget says, and they count against the budget afterwards. This is why budgets work together with replicas and spreading (part 17): three replicas in three zones, a budget of maxUnavailable: 1, and a drain can only ever take one of them at a time, while a zone failure still leaves two running.
Some rules of thumb for a junior on call:
- Every Deployment with two or more replicas that serves users gets a PDB.
- Prefer
maxUnavailable: 1overminAvailable: N. It keeps working when someone scales the Deployment up or down. - A single-replica app cannot have a useful budget. Either accept downtime during maintenance or run two replicas.
- Check
kubectl get pdb -Abefore an upgrade. Any row withALLOWED DISRUPTIONS 0will block it.
cordon, drain and uncordon
Three commands handle node maintenance:
kubectl cordon <node>marks the node unschedulable. New Pods stay off; running Pods keep running.kubectl get nodesshowsSchedulingDisabled.kubectl drain <node> --ignore-daemonsetscordons the node and then evicts its Pods through the Eviction API, respecting PDBs and grace periods. DaemonSet Pods (part 15) are skipped because their controller would put them straight back; without the flag, drain refuses to start. Pods that useemptyDirneed--delete-emptydir-data, because that data is lost. Bare Pods with no controller need--force, because nothing will recreate them anywhere else.kubectl uncordon <node>allows scheduling again. Pods that moved away do not come back on their own.
A PDB that allows zero disruptions blocks a drain forever, and that is a common reason upgrades stall. A budget like minAvailable: 3 for a three-replica app reads as safe but means “never evict anything.” Set the budget below the replica count, or use maxUnavailable: 1.
Try it: taint, preempt and drain
Use the cluster from part 17. Node names start with k8s-ep16- in our output.
1. Reserve a node with a taint.
kubectl get node k8s-ep16-control-plane -o jsonpath='{.spec.taints}{"\n"}'
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule
kubectl describe node k8s-ep16-worker3 | grep -A1 TaintsExplain this command
kubectl get node k8s-ep16-control-plane -o jsonpath='{.spec.taints}{"\n"}'
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule
kubectl describe node k8s-ep16-worker3 | grep -A1 TaintskubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.nodeThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.k8s-ep16-control-planeThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.jsonpath='{.spec.taints}{"\n"}'A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
Explain this command
kubectl get node k8s-ep16-control-plane -o jsonpath='{.spec.taints}{"\n"}'
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule
kubectl describe node k8s-ep16-worker3 | grep -A1 TaintskubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.taintUpdate the taints on one or more nodes. The taint docs show kubectl taint nodes NODE KEY=VALUE:EFFECT, and a trailing hyphen removes that taint.nodesThe resource type.k8s-ep16-worker3The node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.dedicated=gpu:NoScheduleThe taint, written as key=value:effect. A trailing hyphen removes that taint.
Explain this command
kubectl get node k8s-ep16-control-plane -o jsonpath='{.spec.taints}{"\n"}'
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule
kubectl describe node k8s-ep16-worker3 | grep -A1 TaintskubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.describeShow details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.nodeThe resource type.k8s-ep16-worker3The node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.|A shell pipe. The output of the command on the left becomes the input of the command on the right.grepShell. Prints input lines that match a pattern.-A1Also print 1 line after each matching line.TaintsThe pattern grep looks for. Lines that match it are printed.
[{"effect":"NoSchedule","key":"node-role.kubernetes.io/control-plane"}]
node/k8s-ep16-worker3 tainted
Taints: dedicated=gpu:NoSchedule
Unschedulable: false
Save a plain six-replica Deployment as spread-web.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 6
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.29-alpine
kubectl apply -f spread-web.yaml
kubectl rollout status deploy/web
kubectl get pods -l app=web -o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort | uniq -cExplain this command
kubectl apply -f spread-web.yaml
kubectl rollout status deploy/web
kubectl get pods -l app=web -o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort | uniq -ckubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.spread-web.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f spread-web.yaml
kubectl rollout status deploy/web
kubectl get pods -l app=web -o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort | uniq -ckubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.rolloutThe command group for rollout actions.statusShow the status of the rollout. By default it watches the latest rollout until it is done. You can pass --watch=false if you do not want to wait.deploy/webThe resource written as type/name: deploy/web.
Explain this command
kubectl apply -f spread-web.yaml
kubectl rollout status deploy/web
kubectl get pods -l app=web -o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort | uniq -ckubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.-lShort form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.app=webThe label selector passed to -l. It keeps only the objects whose labels match this query.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}'A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.|A shell pipe. The output of the command on the left becomes the input of the command on the right.sortShell. Sorts the input lines.|A shell pipe. The output of the command on the left becomes the input of the command on the right.uniqShell. Reports or filters repeated lines. With -c it prints a count in front of each unique line.-cWith uniq, print a count in front of each unique line.
3 k8s-ep16-worker
3 k8s-ep16-worker2
Nothing on worker3. Now a Pod that tolerates the taint and asks for that node. Save as gpu-job-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: trainer
spec:
nodeSelector:
kubernetes.io/hostname: k8s-ep16-worker3
tolerations:
- key: dedicated
operator: Equal
value: gpu
effect: NoSchedule
containers:
- name: trainer
image: nginx:1.29-alpine
Change the hostname to your node’s name before you apply it.
kubectl apply -f gpu-job-pod.yaml
kubectl get pod trainer -o wideExplain this command
kubectl apply -f gpu-job-pod.yaml
kubectl get pod trainer -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.gpu-job-pod.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f gpu-job-pod.yaml
kubectl get pod trainer -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.trainerThe object name.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.wideAn output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
NAME READY STATUS RESTARTS AGE IP NODE ...
trainer 1/1 Running 0 5s 10.244.2.17 k8s-ep16-worker3 ...
Clean up and remove the taint (the trailing - deletes it):
kubectl delete deploy web
kubectl delete pod trainer
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule-Explain this command
kubectl delete deploy web
kubectl delete pod trainer
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule-kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.deleteDelete resources by file names, stdin, resources and names, or by resources and label selector.deployThe resource type.webThe object name.
Explain this command
kubectl delete deploy web
kubectl delete pod trainer
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule-kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.deleteDelete resources by file names, stdin, resources and names, or by resources and label selector.podThe resource type.trainerThe object name.
Explain this command
kubectl delete deploy web
kubectl delete pod trainer
kubectl taint nodes k8s-ep16-worker3 dedicated=gpu:NoSchedule-kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.taintUpdate the taints on one or more nodes. The taint docs show kubectl taint nodes NODE KEY=VALUE:EFFECT, and a trailing hyphen removes that taint.nodesThe resource type.k8s-ep16-worker3The node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.dedicated=gpu:NoSchedule-The taint, written as key=value:effect. A trailing hyphen removes that taint.
2. NoExecute evicts running Pods. Save as tolerate-briefly.yaml:
apiVersion: v1
kind: Pod
metadata:
name: patient
spec:
nodeSelector:
kubernetes.io/hostname: k8s-ep16-worker
tolerations:
- key: maintenance
operator: Exists
effect: NoExecute
tolerationSeconds: 20
containers:
- name: app
image: nginx:1.29-alpine
---
apiVersion: v1
kind: Pod
metadata:
name: impatient
spec:
nodeSelector:
kubernetes.io/hostname: k8s-ep16-worker
containers:
- name: app
image: nginx:1.29-alpine
kubectl apply -f tolerate-briefly.yaml
kubectl wait --for=condition=Ready pod/patient pod/impatient
kubectl get pod impatient -o jsonpath='{range .spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'Explain this command
kubectl apply -f tolerate-briefly.yaml
kubectl wait --for=condition=Ready pod/patient pod/impatient
kubectl get pod impatient -o jsonpath='{range .spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.tolerate-briefly.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f tolerate-briefly.yaml
kubectl wait --for=condition=Ready pod/patient pod/impatient
kubectl get pod impatient -o jsonpath='{range .spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.waitWait for a condition on one or more resources.--for=condition=ReadyThe condition to wait for. Here kubectl waits until the condition named after --for is met.pod/patientThe resource written as type/name: pod/patient.pod/impatientThe resource written as type/name: pod/impatient.
Explain this command
kubectl apply -f tolerate-briefly.yaml
kubectl wait --for=condition=Ready pod/patient pod/impatient
kubectl get pod impatient -o jsonpath='{range .spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.impatientThe object name.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.jsonpath='{range .spec.tolerations[*]}{.key} {.effect} {.tolerationSeconds}{"\n"}{end}'A jsonpath output format. The get docs say jsonpath prints the fields the expression selects. The lesson uses this path to print the fields named in the command.
pod/patient condition met
pod/impatient condition met
node.kubernetes.io/not-ready NoExecute 300
node.kubernetes.io/unreachable NoExecute 300
Those two tolerations were added for you. Now taint the node, check after 5 seconds and again 20 seconds later:
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messageExplain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.taintUpdate the taints on one or more nodes. The taint docs show kubectl taint nodes NODE KEY=VALUE:EFFECT, and a trailing hyphen removes that taint.nodesThe resource type.k8s-ep16-workerThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.maintenance=true:NoExecuteThe taint, written as key=value:effect. A trailing hyphen removes that taint.
Explain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagesleepShell. Waits the given number of seconds.5How many seconds sleep waits before the next command runs.
Explain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.patientThe object name.impatientThe object name.
Explain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagesleepShell. Waits the given number of seconds.20How many seconds sleep waits before the next command runs.
Explain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.patientThe object name.impatientThe object name.
Explain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute
sleep 5; kubectl get pods patient impatient
sleep 20; kubectl get pods patient impatient
kubectl get events --field-selector reason=TaintManagerEviction -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.eventsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.--field-selectorFilter the list by field. The get docs treat --field-selector as separate from a label selector.reason=TaintManagerEvictionThe field query passed to --field-selector: reason=TaintManagerEviction.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messageA custom table. custom-columns is an output format. The get examples write each column as a heading, a colon, and a JSONPath.
node/k8s-ep16-worker tainted
NAME READY STATUS RESTARTS AGE
patient 1/1 Running 0 6s
Error from server (NotFound): pods "impatient" not found
Error from server (NotFound): pods "patient" not found
Error from server (NotFound): pods "impatient" not found
OBJECT MESSAGE
impatient Marking for deletion Pod k8s-from-zero/impatient
patient Marking for deletion Pod k8s-from-zero/patient
These were bare Pods, so nothing replaced them. Pods of a Deployment would be recreated on other nodes. Remove the taint:
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute-Explain this command
kubectl taint nodes k8s-ep16-worker maintenance=true:NoExecute-kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.taintUpdate the taints on one or more nodes. The taint docs show kubectl taint nodes NODE KEY=VALUE:EFFECT, and a trailing hyphen removes that taint.nodesThe resource type.k8s-ep16-workerThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.maintenance=true:NoExecute-The taint, written as key=value:effect. A trailing hyphen removes that taint.
3. Preemption. Save two classes as priorityclasses.yaml:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: batch-low
value: 1000
globalDefault: false
description: "Batch work that may be preempted."
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: checkout-high
value: 100000
globalDefault: false
description: "Customer-facing services."
Our kind nodes report 8 allocatable CPUs each; check yours with kubectl get nodes -o custom-columns=NAME:.metadata.name,CPU:.status.allocatable.cpu and scale the requests below so two batch Pods fill most of a node. Save as batch.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: batch
spec:
replicas: 6
selector:
matchLabels:
app: batch
template:
metadata:
labels:
app: batch
spec:
priorityClassName: batch-low
containers:
- name: batch
image: nginx:1.29-alpine
resources:
requests:
cpu: "3"
kubectl apply -f priorityclasses.yaml
kubectl apply -f batch.yaml
kubectl get pods -l app=batch -o wide
kubectl describe node k8s-ep16-worker | grep -E "^ cpu"Explain this command
kubectl apply -f priorityclasses.yaml
kubectl apply -f batch.yaml
kubectl get pods -l app=batch -o wide
kubectl describe node k8s-ep16-worker | grep -E "^ cpu"kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.priorityclasses.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f priorityclasses.yaml
kubectl apply -f batch.yaml
kubectl get pods -l app=batch -o wide
kubectl describe node k8s-ep16-worker | grep -E "^ cpu"kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.batch.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f priorityclasses.yaml
kubectl apply -f batch.yaml
kubectl get pods -l app=batch -o wide
kubectl describe node k8s-ep16-worker | grep -E "^ cpu"kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.-lShort form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.app=batchThe label selector passed to -l. It keeps only the objects whose labels match this query.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.wideAn output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
Explain this command
kubectl apply -f priorityclasses.yaml
kubectl apply -f batch.yaml
kubectl get pods -l app=batch -o wide
kubectl describe node k8s-ep16-worker | grep -E "^ cpu"kubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.describeShow details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.nodeThe resource type.k8s-ep16-workerThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.|A shell pipe. The output of the command on the left becomes the input of the command on the right.grepShell. Prints input lines that match a pattern.-ETell grep to treat the pattern as an extended regular expression."^ cpu"The extended regular expression grep looks for. Lines that match it are printed.
NAME READY STATUS RESTARTS AGE IP NODE ...
batch-5bd8dd9495-cv74v 1/1 Running 0 0s 10.244.3.27 k8s-ep16-worker2 ...
batch-5bd8dd9495-gtnks 1/1 Running 0 0s 10.244.1.20 k8s-ep16-worker ...
batch-5bd8dd9495-l57cb 1/1 Running 0 0s 10.244.3.26 k8s-ep16-worker2 ...
batch-5bd8dd9495-mw2hl 1/1 Running 0 0s 10.244.2.18 k8s-ep16-worker3 ...
batch-5bd8dd9495-pf4d9 1/1 Running 0 0s 10.244.2.19 k8s-ep16-worker3 ...
batch-5bd8dd9495-sntn5 1/1 Running 0 0s 10.244.1.21 k8s-ep16-worker ...
cpu 6100m (76%) 0 (0%)
Each worker has 1.9 CPUs left. Save as checkout.yaml, a Pod that needs 4:
apiVersion: v1
kind: Pod
metadata:
name: checkout
spec:
priorityClassName: checkout-high
containers:
- name: checkout
image: nginx:1.29-alpine
resources:
requests:
cpu: "4"
kubectl apply -f checkout.yaml
sleep 10; kubectl get pod checkout -o wide
kubectl get pods -l app=batch
kubectl get events --field-selector reason=Preempted -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messageExplain this command
kubectl apply -f checkout.yaml
sleep 10; kubectl get pod checkout -o wide
kubectl get pods -l app=batch
kubectl get events --field-selector reason=Preempted -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.checkout.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f checkout.yaml
sleep 10; kubectl get pod checkout -o wide
kubectl get pods -l app=batch
kubectl get events --field-selector reason=Preempted -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagesleepShell. Waits the given number of seconds.10How many seconds sleep waits before the next command runs.
Explain this command
kubectl apply -f checkout.yaml
sleep 10; kubectl get pod checkout -o wide
kubectl get pods -l app=batch
kubectl get events --field-selector reason=Preempted -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.checkoutThe object name.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.wideAn output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
Explain this command
kubectl apply -f checkout.yaml
sleep 10; kubectl get pod checkout -o wide
kubectl get pods -l app=batch
kubectl get events --field-selector reason=Preempted -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.-lShort form of --selector. A label query. The get docs say it supports '=', '==', '!=', 'in' and 'notin', and that matching objects must satisfy every constraint.app=batchThe label selector passed to -l. It keeps only the objects whose labels match this query.
Explain this command
kubectl apply -f checkout.yaml
sleep 10; kubectl get pod checkout -o wide
kubectl get pods -l app=batch
kubectl get events --field-selector reason=Preempted -o custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messagekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.eventsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.--field-selectorFilter the list by field. The get docs treat --field-selector as separate from a label selector.reason=PreemptedThe field query passed to --field-selector: reason=Preempted.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.custom-columns=OBJECT:.involvedObject.name,MESSAGE:.messageA custom table. custom-columns is an output format. The get examples write each column as a heading, a colon, and a JSONPath.
NAME READY STATUS RESTARTS AGE IP NODE ...
checkout 1/1 Running 0 10s 10.244.2.20 k8s-ep16-worker3 ...
NAME READY STATUS RESTARTS AGE
batch-5bd8dd9495-cv74v 1/1 Running 0 11s
batch-5bd8dd9495-gtnks 1/1 Running 0 11s
batch-5bd8dd9495-l57cb 1/1 Running 0 11s
batch-5bd8dd9495-m9k7l 0/1 Pending 0 10s
batch-5bd8dd9495-pf4d9 1/1 Running 0 11s
batch-5bd8dd9495-sntn5 1/1 Running 0 11s
OBJECT MESSAGE
batch-5bd8dd9495-mw2hl Preempted by pod dd0352a2-39d8-4fe7-be1f-b94c22d3a148 on node k8s-ep16-worker3
The batch Pod mw2hl was evicted and checkout took its place. The Deployment made a replacement, m9k7l here (yours has another suffix), which now waits. Describe the Pending batch Pod:
kubectl describe $(kubectl get pods -l app=batch --field-selector=status.phase=Pending -o name) | grep FailedSchedulingExplain this command
kubectl describe $(kubectl get pods -l app=batch --field-selector=status.phase=Pending -o name) | grep FailedSchedulingkubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.describeShow details of a specific resource or group of resources. The describe docs say this includes related resources such as events or controllers.$(kubectl get pods -l app=batch --field-selector=status.phase=Pending -o name)A command substitution. The inner kubectl command prints the name of the Pending Pod, and describe uses that name.|A shell pipe. The output of the command on the left becomes the input of the command on the right.grepShell. Prints input lines that match a pattern.FailedSchedulingThe pattern grep looks for. FailedScheduling is the event reason the scheduler writes when it cannot place a Pod.
Warning FailedScheduling 10s (x2 over 10s) default-scheduler 0/4 nodes are available: 1 node(s) had untolerated taint(s), 3 Insufficient cpu. preemption: 0/4 nodes are available: 1 Preemption is not helpful for scheduling, 3 No preemption victims found for incoming pod.
It cannot preempt anything, because every other Pod has the same or higher priority. Clean up and wait until the Pods are gone, so they do not show up in the next step:
kubectl delete pod checkout
kubectl delete deploy batch
kubectl delete -f priorityclasses.yaml
kubectl wait --for=delete pod --all --timeout=60sExplain this command
kubectl delete pod checkout
kubectl delete deploy batch
kubectl delete -f priorityclasses.yaml
kubectl wait --for=delete pod --all --timeout=60skubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.deleteDelete resources by file names, stdin, resources and names, or by resources and label selector.podThe resource type.checkoutThe object name.
Explain this command
kubectl delete pod checkout
kubectl delete deploy batch
kubectl delete -f priorityclasses.yaml
kubectl wait --for=delete pod --all --timeout=60skubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.deleteDelete resources by file names, stdin, resources and names, or by resources and label selector.deployThe resource type.batchThe object name.
Explain this command
kubectl delete pod checkout
kubectl delete deploy batch
kubectl delete -f priorityclasses.yaml
kubectl wait --for=delete pod --all --timeout=60skubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.deleteDelete resources by file names, stdin, resources and names, or by resources and label selector.-fShort form of --filename. For delete, the file that contains the resource to delete.priorityclasses.yamlThe file named by --filename. delete removes the resources that file describes.
Explain this command
kubectl delete pod checkout
kubectl delete deploy batch
kubectl delete -f priorityclasses.yaml
kubectl wait --for=delete pod --all --timeout=60skubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.waitWait for a condition on one or more resources.--for=deleteThe condition to wait for. Here kubectl waits until the condition named after --for is met.podThe resource type.--allSelect every object of the given type in the namespace, instead of naming them.--timeout=60sHow long to wait before giving up. This command passes 60s.
4. A budget that blocks a drain. Save web3.yaml (the Deployment from step 1 with replicas: 3) and pdb.yaml:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
spec:
minAvailable: 3
selector:
matchLabels:
app: web
kubectl apply -f web3.yaml -f pdb.yaml
kubectl get pods -o wide
kubectl get pdb web-pdbExplain this command
kubectl apply -f web3.yaml -f pdb.yaml
kubectl get pods -o wide
kubectl get pdb web-pdbkubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.applyApply a configuration to a resource by file name or stdin. The apply docs say the resource is created if it does not exist yet. JSON and YAML are accepted.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.web3.yamlThe file named by --filename. apply creates the objects or updates them to match this file.-fShort form of --filename. The file, directory or URL that contains the configuration to apply.pdb.yamlThe file named by --filename. apply creates the objects or updates them to match this file.
Explain this command
kubectl apply -f web3.yaml -f pdb.yaml
kubectl get pods -o wide
kubectl get pdb web-pdbkubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.wideAn output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
Explain this command
kubectl apply -f web3.yaml -f pdb.yaml
kubectl get pods -o wide
kubectl get pdb web-pdbkubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.pdbThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.web-pdbThe object name.
NAME READY STATUS RESTARTS AGE IP NODE ...
web-5b756874b6-jrmzf 1/1 Running 0 1s 10.244.2.23 k8s-ep16-worker3 ...
web-5b756874b6-s72bg 1/1 Running 0 1s 10.244.1.23 k8s-ep16-worker ...
web-5b756874b6-wm9cz 1/1 Running 0 1s 10.244.3.29 k8s-ep16-worker2 ...
NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
web-pdb 3 N/A 0 1s
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=20sExplain this command
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=20skubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.drainDrain a node in preparation for maintenance. Safe evictions respect PodDisruptionBudgets. The drain docs say --ignore-daemonsets is needed when DaemonSet Pods are present.k8s-ep16-workerThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.--ignore-daemonsetsSkip DaemonSet Pods so drain can finish. The drain docs say the DaemonSet controller would otherwise recreate them on the same node.--timeout=20sHow long to wait before giving up. This command passes 20s.
node/k8s-ep16-worker cordoned
Warning: ignoring DaemonSet-managed Pods: kube-system/kindnet-kxjm7, kube-system/kube-proxy-2rgj6
evicting pod k8s-from-zero/web-5b756874b6-s72bg
error when evicting pods/"web-5b756874b6-s72bg" -n "k8s-from-zero" (will retry after 5s): Cannot evict pod as it would violate the pod's disruption budget.
...
error: unable to drain node "k8s-ep16-worker" due to error: error when evicting pods/"web-5b756874b6-s72bg" -n "k8s-from-zero": global timeout reached: 20s, continuing command...
Without --timeout, drain would retry forever. The node is still cordoned:
kubectl get nodesExplain this command
kubectl get nodeskubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.nodesThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.
NAME STATUS ROLES AGE VERSION
k8s-ep16-control-plane Ready control-plane 14m v1.37.0
k8s-ep16-worker Ready,SchedulingDisabled <none> 11m v1.37.0
k8s-ep16-worker2 Ready <none> 11m v1.37.0
k8s-ep16-worker3 Ready <none> 11m v1.37.0
5. Loosen the budget and drain again.
kubectl patch pdb web-pdb --type=merge -p '{"spec":{"minAvailable":2}}'
kubectl get pdb web-pdb
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=60s
kubectl get pods -o wideExplain this command
kubectl patch pdb web-pdb --type=merge -p '{"spec":{"minAvailable":2}}'
kubectl get pdb web-pdb
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=60s
kubectl get pods -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.patchUpdate fields of a resource using a strategic merge patch, a JSON merge patch, or a JSON patch. The patch docs say JSON and YAML are accepted.pdbThe resource type.web-pdbThe object name.--type=mergeThe patch type. merge is a JSON merge patch.-pShort form of --patch. The patch to apply, written here as JSON.'{"spec":{"minAvailable":2}}'The patch document, written as JSON. Only the fields it names are changed.
Explain this command
kubectl patch pdb web-pdb --type=merge -p '{"spec":{"minAvailable":2}}'
kubectl get pdb web-pdb
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=60s
kubectl get pods -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.pdbThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.web-pdbThe object name.
Explain this command
kubectl patch pdb web-pdb --type=merge -p '{"spec":{"minAvailable":2}}'
kubectl get pdb web-pdb
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=60s
kubectl get pods -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.drainDrain a node in preparation for maintenance. Safe evictions respect PodDisruptionBudgets. The drain docs say --ignore-daemonsets is needed when DaemonSet Pods are present.k8s-ep16-workerThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.--ignore-daemonsetsSkip DaemonSet Pods so drain can finish. The drain docs say the DaemonSet controller would otherwise recreate them on the same node.--timeout=60sHow long to wait before giving up. This command passes 60s.
Explain this command
kubectl patch pdb web-pdb --type=merge -p '{"spec":{"minAvailable":2}}'
kubectl get pdb web-pdb
kubectl drain k8s-ep16-worker --ignore-daemonsets --timeout=60s
kubectl get pods -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.wideAn output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
poddisruptionbudget.policy/web-pdb patched
NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE
web-pdb 2 N/A 1 21s
node/k8s-ep16-worker already cordoned
Warning: ignoring DaemonSet-managed Pods: kube-system/kindnet-kxjm7, kube-system/kube-proxy-2rgj6
evicting pod k8s-from-zero/web-5b756874b6-s72bg
pod/web-5b756874b6-s72bg evicted
node/k8s-ep16-worker drained
NAME READY STATUS RESTARTS AGE IP NODE ...
web-5b756874b6-4jpzq 1/1 Running 0 2s 10.244.3.30 k8s-ep16-worker2 ...
web-5b756874b6-jrmzf 1/1 Running 0 23s 10.244.2.23 k8s-ep16-worker3 ...
web-5b756874b6-wm9cz 1/1 Running 0 23s 10.244.3.29 k8s-ep16-worker2 ...
The replacement landed on worker2, because worker is cordoned. Finish the maintenance with:
kubectl uncordon k8s-ep16-worker
kubectl get pods -o wideExplain this command
kubectl uncordon k8s-ep16-worker
kubectl get pods -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.uncordonMark a node as schedulable again, reversing kubectl cordon or the unschedulable mark left by drain.k8s-ep16-workerThe node name from the lab cluster. The lesson says reader clusters named k8s-multi will use that prefix instead of k8s-ep16.
Explain this command
kubectl uncordon k8s-ep16-worker
kubectl get pods -o widekubectlThe Kubernetes command-line client. Subcommands and flags are documented under kubernetes.io/docs/reference/kubectl/.getDisplay one or many resources. kubectl get prints a table of the most important information about the resources you name.podsThe resource type to display. kubectl get points you to kubectl api-resources for the full list of types the server supports.-oShort form of --output. It selects the output format. For get, the formats include json, yaml, name, jsonpath, custom-columns and wide.wideAn output format: the default table plus more columns. The get examples say it adds more information, such as the node name. The lesson's output adds IP and NODE.
The node is Ready again, and the three Pods stay where they are: uncordon does not move them back. Clean up with kubectl delete -f web3.yaml -f pdb.yaml. If you made the extra cluster in part 17 and are done with it, kind delete cluster --name k8s-multi removes it.
When it goes wrong
- Pods avoid a node and you do not know why.
kubectl describe node <name> | grep -A3 Taints. A forgottenNoScheduletaint, or a leftovernode.kubernetes.io/unschedulablefrom a cordon, keeps Pods off. - A toleration “does nothing”. It only permits. Add node affinity or a
nodeSelectorto pull the Pod onto the tainted node. - A high-priority Pod is still Pending. Preemption found no victims: other Pods have equal or higher priority, or removing them would still not free enough requested resources. Read the
FailedSchedulingevent; the part afterpreemption:says why. kubectl drainhangs on “Cannot evict pod”. A PDB allows zero disruptions.kubectl get pdb -AshowsALLOWED DISRUPTIONS 0. Scale the app up, or lowerminAvailable(or usemaxUnavailable: 1); do not delete the PDB in a hurry on a production app.- Drain refuses to start. In our lab it printed
cannot delete DaemonSet-managed Pods (use --ignore-daemonsets to ignore)andcannot delete Pods with local storage (use --delete-emptydir-data to override). Add--ignore-daemonsets, and--delete-emptydir-datawhen losing that scratch data is fine. - Drain says
cannot delete Pods that declare no controller. A bare Pod (no Deployment, Job or other owner) would be gone for good. Recreate it under a controller, or use--forceif you accept losing it.
Cheat sheet
| Task | Command or field | Note |
|---|---|---|
| Taint a node | kubectl taint nodes <n> key=value:NoSchedule |
effects: NoSchedule, PreferNoSchedule, NoExecute |
| Remove a taint | kubectl taint nodes <n> key=value:NoSchedule- |
trailing - |
| See taints | kubectl describe node <n> | grep -A3 Taints |
or .spec.taints |
| Tolerate a taint | spec.tolerations[] key, operator, value, effect |
permits, does not attract |
| Stay a while under NoExecute | tolerationSeconds: 20 |
default 300 for not-ready, unreachable |
| Define a priority | kind: PriorityClass, value: |
up to 1 billion for your classes |
| Use it | spec.priorityClassName |
no class: priority 0 |
| Queue first, no evictions | preemptionPolicy: Never |
on the PriorityClass |
| See preemptions | kubectl get events --field-selector reason=Preempted |
|
| Limit voluntary disruption | kind: PodDisruptionBudget, minAvailable or maxUnavailable |
number or percent |
| Check a budget | kubectl get pdb |
ALLOWED DISRUPTIONS |
| Stop new Pods on a node | kubectl cordon <n> |
SchedulingDisabled |
| Empty a node safely | kubectl drain <n> --ignore-daemonsets --timeout=5m |
uses the Eviction API |
| Back in service | kubectl uncordon <n> |
Pods do not move back |
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
namespace: k8s-from-zero
spec:
maxUnavailable: 1
selector:
matchLabels:
app: web
Recap and what is next
- A taint keeps Pods off a node; a toleration lets a Pod in but does not pull it there.
NoExecutealso evicts running Pods. - PriorityClass ranks Pods; when the cluster is full, the scheduler preempts lower-priority Pods to place a higher one.
- A PodDisruptionBudget limits voluntary disruptions, and only tools that use the Eviction API, such as
kubectl drain, respect it. - Maintenance is cordon, drain, work, uncordon, with budgets that allow at least one disruption.
Next: Kubernetes from Zero, part 19, Ingress and Gateway API basics, coming tomorrow.
Command explanations and quoted passages in this lesson come from or adapt the kubectl reference and the Kubernetes documentation, © The Kubernetes Authors, licensed under CC BY 4.0. We shortened and edited some passages. Kubernetes® is a registered trademark of The Linux Foundation. aitamer.news is not affiliated with or endorsed by The Linux Foundation or the CNCF.

The Campfire
CommentsThanks. Your comment is waiting for the desk. Once it is approved it appears here within about a minute.
Add a comment