Kubernetes Taints and Tolerations

Prerequisites

Taint Beginner Demo: NoSchedule

kubectl taint nodes minikube dedicated-app=my-dedi-app-a:NoSchedule
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 3600']

restartPolicy: Never
terminationGracePeriodSeconds: 0
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Pending 0 5s
kubectl describe pod/mybusypodName:               mybusypod
Labels: app=my-dedi-app-a
Status: Pending
Containers:
my-dedi-container-a:
Image: busybox

Conditions:
Type Status
PodScheduled False
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 25s default-scheduler 0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 3600']

restartPolicy: Never
terminationGracePeriodSeconds: 0

tolerations:
- key: "dedicated-app"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoSchedule"
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 4s
kubectl describe pod/mybusypodName:               mybusypod
Node: minikube/10.0.2.15
Start Time: Mon, 11 Feb 2019 07:53:59 +0200
Labels: app=my-dedi-app-a
Status: Running
Containers:
my-dedi-container-a:
Command:
State: Running
Ready: True
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Tolerations: dedicated-app=my-dedi-app-a:NoSchedule
node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 11s default-scheduler Successfully assigned default/mybusypod to minikube
Normal Pulled 10s kubelet, minikube Container image "busybox" already present on machine
Normal Created 10s kubelet, minikube Created container
Normal Started 10s kubelet, minikube Started container
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted

NoExecute Taint

kubectl taint nodes minikube dedicated-app-exec=my-dedi-app-a:NoExecute
node/minikube tainted
kubectl describe node | head -n13Name:               minikube
Roles: master
Taints: dedicated-app-exec=my-dedi-app-a:NoExecute
dedicated-app=my-dedi-app-a:NoSchedule
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 3600']

restartPolicy: Never
terminationGracePeriodSeconds: 0

tolerations:
- key: "dedicated-app"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoSchedule"
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Pending 0 3s
kubectl describe pod/mybusypodName:               mybusypod
Labels: app=my-dedi-app-a
Status: Pending
IP:
Containers:
my-dedi-container-a:
Image: busybox
Conditions:
Type Status
PodScheduled False
Tolerations: dedicated-app=my-dedi-app-a:NoSchedule
node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 17s (x2 over 17s) default-scheduler 0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.

NoExecute Toleration

nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 3600']

restartPolicy: Never
terminationGracePeriodSeconds: 0

tolerations:
- key: "dedicated-app"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoSchedule"

- key: "dedicated-app-exec"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoExecute"
tolerationSeconds: 60
kubectl create -f mybusybox.yaml
pod/mybusypod created
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 2s
kubectl get pods
No resources found.

which-end: frontend

nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
which-end: frontend
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 10']

restartPolicy: Never
terminationGracePeriodSeconds: 0

tolerations:
- key: "dedicated-app"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoSchedule"
- key: "dedicated-app-exec"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoExecute"
tolerationSeconds: 60
kubectl taint nodes minikube which-end=frontend:NoSchedule
node/minikube tainted
kubectl describe node | head -n13
Name: minikube
Taints: dedicated-app-exec=my-dedi-app-a:NoExecute
dedicated-app=my-dedi-app-a:NoSchedule
which-end=frontend:NoSchedule
Tolerations:     dedicated-app=my-dedi-app-a:NoSchedule
dedicated-app-exec=my-dedi-app-a:NoExecute for 60s
node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Pending 0 2s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 12s (x2 over 12s) default-scheduler 0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted

Wildcard Global Tolerations

- key: "which-end"
operator: "Exists"
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
which-end: frontend
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 10']

restartPolicy: Never
terminationGracePeriodSeconds: 0

tolerations:
- key: "dedicated-app"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoSchedule"
- key: "dedicated-app-exec"
operator: "Equal"
value: "my-dedi-app-a"
effect: "NoExecute"
tolerationSeconds: 60

- key: "which-end"
operator: "Exists"
kubectl get podsNAME        READY   STATUS    RESTARTS   AGE
mybusypod 1/1 Running 0 3s
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Completed 0 18s
Tolerations:     dedicated-app=my-dedi-app-a:NoSchedule
dedicated-app-exec=my-dedi-app-a:NoExecute for 60s
node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
which-end
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted

Tolerate All Taints

tolerations:
- operator: "Exists"
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
which-end: frontend
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 10']

restartPolicy: Never
terminationGracePeriodSeconds: 0

tolerations:
- operator: "Exists"
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 2s
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 7s
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 12s
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Completed 0 16s
Tolerations:
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted

PreferNoSchedule

Taints:             dedicated-app-exec=my-dedi-app-a:NoExecute
dedicated-app=my-dedi-app-a:NoSchedule
which-end=frontend:NoSchedule
kubectl taint nodes minikube dedicated-app-exec:NoExecute-
kubectl taint nodes minikube dedicated-app:NoSchedule-
kubectl taint nodes minikube which-end:NoSchedule-
node/minikube untainted
node/minikube untainted
node/minikube untainted
Taints:             <none>
kubectl taint nodes minikube dedicated-app=my-dedi-app-a:PreferNoSchedule
node/minikube tainted
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
which-end: frontend
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 10']

restartPolicy: Never
terminationGracePeriodSeconds: 0
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 ContainerCreating 0 2s
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 5s
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 8s
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Completed 0 13s
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted

Running Pods on Unschedulable Nodes

kubectl describe node | head -n13
Name: minikube
Taints: dedicated-app=my-dedi-app-a:PreferNoSchedule
Unschedulable: false
kubectl cordon minikube
node/minikube cordoned
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get podsNAME READY STATUS RESTARTS AGE
mybusypod 0/1 Pending 0 3s
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 7s default-scheduler 0/1 nodes are available: 1 node(s) were unschedulable.
kubectl uncordon minikube
node/minikube uncordoned
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 45s
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 52s
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Completed 0 60s
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted
nano mybusybox.yamlapiVersion: v1
kind: Pod
metadata:
name: mybusypod
labels:
app: my-dedi-app-a
which-end: frontend
spec:
containers:
- name: my-dedi-container-a
image: busybox
imagePullPolicy: IfNotPresent

command: ['sh', '-c', 'sleep 10']

restartPolicy: Never
terminationGracePeriodSeconds: 0
tolerations:
- key: "node.kubernetes.io/unschedulable"
operator: "Exists"
kubectl cordon minikube
node/minikube cordoned
kubectl create -f mybusybox.yaml
pod/mybusypod created
kubectl get pods
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 2s
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 7s
NAME READY STATUS RESTARTS AGE
mybusypod 1/1 Running 0 11s
NAME READY STATUS RESTARTS AGE
mybusypod 0/1 Completed 0 15s
kubectl uncordon minikube
node/minikube uncordoned
kubectl delete -f mybusybox.yaml
pod "mybusypod" deleted

Cleanup

kubectl describe node | head -n13Name:               minikube
Taints: dedicated-app=my-dedi-app-a:PreferNoSchedule
Unschedulable: false
Conditions:
kubectl taint nodes minikube dedicated-app:PreferNoSchedule-
node/minikube untainted

Original Source

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Overview of python|python tutorial 1

Why is Python good for Blockchain?

Closure Patterns in Swift

What if I wanted to submit remote PySpark jobs to AWS EMR without worrying about library dependen…

Simple programming concept and their basics

Working of GPIO

Panic Mode, every SaaS/product development team should have one

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

MYSQL Database Instance on Red Hat Openshift

Monitoring Camel K applications using Prometheus and Grafana

Say hello to Berglas — a way to keep your Secrets a Secret

Backup and Restore using OADP in OpenShift Cluster