CERTIFIED KUBERNETES ADMINISTRATOR
-------------------------------------------------------------------------
kubernetes tutorial | Scheduling Pods to Nodes | Taints and Tolerations | Demo
Description
----------------------
In this video, you are going to learn the concepts of Scheduling pods to nodes using Taints and Tolerations. we are also going to see a demo on the Taints and Tolerations as well.
Kubernetes - Scheduling Pods to Nodes using Taints and Tolerations
------------------------------------------------------------------------------------------------------------------
1. What are Taints & Tolerations ?
2. Taints & Tolerations – How to ?
3. Taint Effects
4. Taint Effects ... NoSchedule | PreferNoSchedule | NoExecute
5. Taints & Tolerations - Example Use Cases
5. Taint Based Evictions
6. DEMO: Taints and Tolerations
7. Thank you
For suggestions/feedback/doubts contact
email: [email protected]
Happy Learning !!!
============================================================
USEFUL LINKS
----------------------------
API References:
https://kubernetes.io/docs/reference/...
Kubectl Command Reference:
https://kubernetes.io/docs/reference/...
Taints and Tolerations:
https://kubernetes.io/docs/concepts/s...
============================================================
#vsparkz #kubernetes #k8s #containers
DEMO STEPS
-------------------------
Step 1: Access & Inspect the Kubernetes Cluster
$ kubectl cluster-info
$ kubectl get nodes
$ kubectl get pods -n kube-system
Step 2: Check the Taints in the Nodes
$ kubectl get nodes -o json | grep "kubernetes.io/hostname" -C 20
Step 3: Schedule some default pods in worker 1 and worker 2
$ kubectl run nginx-1 --image=nginx --overrides='{"spec": { "nodeSelector": {"kubernetes.io/hostname": "worker01.vsparkz.com"}}}'
$ kubectl run nginx-2 --image=nginx --overrides='{"spec": { "nodeSelector": {"kubernetes.io/hostname": "worker02.vsparkz.com"}}}'
Step 4: Taint the nodes and schedule the pods with tolerations (Effect-NoSchedule)
__=====
Tip:
set .vimrc for yaml indentation's
command:
set ts=2 et cursorcolumn
source .vimrc
=====__
$ kubectl taint node worker01.vsparkz.com application=webserver:NoSchedule
$ kubectl taint node worker02.vsparkz.com environment=caching:NoSchedule
$ kubectl run nginx --image=nginx --dry-run=client -o yaml
Copy the output content and create a file: taint_noschedule.yaml
$ kubectl api-resources
Update the pod definition accordingly(with Tolerations)
$ vim taint_noschedule.yaml
_=======================
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx
spec:
containers:
image: nginx
name: nginx
tolerations:
effect: NoSchedule
key: application
operator: Equal
value: webserver
========================_
$ kubectl apply -f taint_noschedule.yaml
Cleanup Step 4
$ kubectl taint node worker01.vsparkz.com application=webserver:NoSchedule-
$ kubectl taint node worker02.vsparkz.com environment=caching:NoSchedule-
Step 5: Taint the nodes and schedule the pods WITHOUT tolerations (Effect - PreferNoSchedule)
$ kubectl taint node worker01.vsparkz.com application=webserver:PreferNoSchedule
$ kubectl taint node worker02.vsparkz.com environment=caching:NoSchedule
$ kubectl run nginx --image=nginx --dry-run=client -o yaml
Copy the content and create a file: taint_prefernoschedule.yaml
$ vim taint_prefernoschedule.yaml
_=============
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx
spec:
containers:
image: nginx
name: nginx
================_
$ kubectl apply -f taint_prefernoschedule.yaml
Cleanup Step 5
$ kubectl taint node worker01.vsparkz.com application=webserver:PreferNoSchedule-
$ kubectl taint node worker02.vsparkz.com environment=caching:NoSchedule-
Step 6: Taint the nodes and schedule the pods with tolerations (Effect - NoExecute)
$ kubectl taint node worker01.vsparkz.com application=webserver:NoExecute
$ kubectl taint node worker02.vsparkz.com environment=caching:NoExecute
All the existing pods that do not tolerate taint will be evicted
Try to schedule a new pod without taint
$ kubectl run nginx --image=nginx --dry-run=client -o yaml
Copy the content and create a file: taint_noexecute.yaml
$ vim taint_noexecute.yaml
_=========================
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
nodeSelector: {"kubernetes.io/hostname": "worker01.vsparkz.com"}
containers:
image: nginx
name: nginx
tolerations:
effect: NoExecute
operator: Exists
tolerationSeconds: 30
==========================_
Pods will be evicted after 30 seconds
Cleanup Step 6
$ kubectl taint node worker01.vsparkz.com application=webserver:NoExecute-
$ kubectl taint node worker02.vsparkz.com environment=caching:NoExecute-
=============================