Scheduling Pods with Taints and Tolerations in Kubernetes

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will be presented with a three-node cluster. One node is the master, and the other two are worker nodes. You will be responsible for splitting up the two worker nodes and making one of the worker nodes a production (prod) environment node and the other a development (dev) environment node. The purpose of identifying these two types (prod and dev) is to not accidentally deploy pods into the production environment. You will use taints and tolerations to achieve this, and then you will deploy two pods: One pod will be scheduled to the dev environment, and one pod will be scheduled to the prod environment. When you have verified the two pods are up and running and they are located within the correct environments, you may consider this hands-on lab complete.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Taint one of the worker nodes to repel work.
  1. Use the following command to taint the node:

    kubectl taint node <node_name> node-type=prod:NoSchedule
Schedule a pod to the dev environment.
  1. Use the following YAML to specify a pod that will be scheduled to the dev environment:

    apiVersion: v1
    kind: Pod
    metadata:
      name: dev-pod
      labels:
        app: busybox
    spec:
      containers:
      - name: dev
        image: busybox
        command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
  2. Use the following command to create the pod:

    kubectl create -f dev-pod.yaml
Allow a pod to be scheduled to the prod environment.
  1. Use the following YAML to create a deployment and a pod that will tolerate the prod environment:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: prod
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: prod
      template:
        metadata:
          labels:
            app: prod
        spec:
          containers:
          - args:
            - sleep
            - "3600"
            image: busybox
            name: main
          tolerations:
          - key: node-type
            operator: Equal
            value: prod
            effect: NoSchedule
  2. Use the following command to create the pod:

    kubectl create -f prod-deployment.yaml
Verify each pod has been scheduled and verify the toleration.
  1. Use the following command to verify the pods have been scheduled:

    kubectl get pods -o wide

    2.Scale up the deployment:

    kubectl scale deployment/prod --replicas=3
  2. Verify the toleration of the production pod:

    kubectl get pods <pod_name> -o yaml

Additional Resources

You have been given a three-node cluster. Within that cluster, you must perform the following tasks to taint the production node in order to repel work. You will create the necessary taint to properly label one of the nodes “prod.” Then you will deploy two pods — one to each environment. One pod spec will contain the toleration for the taint. You must perform the following tasks in order to complete this hands-on lab:

  • Taint one of the worker nodes to identify the prod environment.
  • Create the YAML spec for a pod that will be scheduled to the dev environment.
  • Create the YAML spec for a pod that will be scheduled to the prod environment.
  • Deploy each pod to their respective environments.
  • Verify each pod has been scheduled successfully to each environment.

For more on Taints and Tolerations, see: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?