Home / How To / Creating Taints and Tolerations in Kubernetes

Creating Taints and Tolerations in Kubernetes



Taints and tolerances work together to ensure that skis are not scheduled on unsuitable nodes. One or more taints can be applied to a node, which means that the node should not accept any ski that does not tolerate taints. The pods that have tolerance can only be distributed on the nodes with taints.

For example, if you want to dedicate certain nodes to the exclusive use of a particular set of skis, you can add a taint to those nodes and then add the respective tolerances to the skis. The arcs with the tolerances are then allowed to use the recessed nodes as well as all other nodes in the cluster. This ensures that pods that do not have tolerance can never be distributed on the nodes with taints.

Node jewelry is the key-value pair associated with an effect. Here are the available effects:

  • NoSchedule : Skis that do not tolerate this pain are not scheduled in the node but the existing skis are not removed from the node.
  • PreferNoSchedule : Kubernetes avoids scheduling discs that do not tolerate this pain on the node.
  • NoExecute : Pod is removed from the node if it is already running on the node and is not scheduled to the node if it is not yet running on the node.

In this article, we will create a pain on a worker node and add tolerance to the skis. This will help us understand the pod that has no tolerance will not be distributed on the processed node with taint on it.

Requirements

  1. Kubernetes Cluster with at least 1 working node.
    If you want to learn how to create a Kubernetes cluster, click here. This guide will help you create a Kubernetes cluster with 1 Master and 2 Nodes on AWS Ubuntu 18.04 EC2 instances.

What We Will Do

  1. Create Taints and Tolerations

Create Taints and Tolerations

First, let's check the nodes available in the cluster.

  kubectl gets nodes # Get current pods in the cluster. [19659015] get-nodes "width =" 750 "height =" 213 "style =" display: block; margin-left: auto; margin-right: auto; "ezimgfmt =" rs rscb1 src ng ngcb1 "class =" ezlazyload "data-ezsrc =" https://www.howtoforge.com/images/create_taints_and_tolerations_in_kubernetes/screenshot_2020-06-26_at_105537_ 

Use "describe" command to control Taints to node01

  cubectl describe node node01 # Describe node01 node to extract more information. 

  describe-node1

In the above screenshot it can be seen that the node has no Taint.

Let's add "app = fronend: NoSchedule" Taint to Node01

  kubectl taint nodes node01 app = fronend: NoSchedule # Add color to the node01 node. 
  cubectl describes node node01 # Extract details for node01 node. 

  add-a-taint-on-node1

In the above screenshot, it may be seen that Node01 has a Taint now .

Create a file and add the following pod definition to it.

  vim my-pod.yml # Create e n pod definition. 
  apiVersion: v1
please: Pod
metadata:
  name: frontend
spec
  container:
  - image: nginx
    name: frontend-nginx 

  pod-with-no-tolerance

This pod definition has no tolerance in it.

To create a pod that has no tolerance, run the following command.

  kubectl create -f my-pod.yml # Create a pod. 
  kubectl get skis # Get details about pod. 

  create-a-pod

Use the "describe" command to get more information about the pod.

  kubectl get skis # Get details on pod. 
  kubectl describes pod frontend #Extract more pod information. 
  19659037] describes the "width =" 750 "height =" 370 "style =" display: block; margin-left: auto; margin-right: auto; "ezimgfmt =" rs rscb1 src ng ngcb1 "class =" ezlazyload "data-ezsrc =" https://www.howtoforge.com/images/create_taints_and_tolerations_in_kubernetes/screenshot_2020-06-26_at_110417_ 

In the above screenshot you can see that the pod was not scheduled, the reason for this is that Node01 has a Taint but there is no Toleration in the Pod.

To create another file with the following pod definition This pod has a tolerance in itself.

  vim my-mysql-pod.yml # Create a pod definition. 
  apiVersion: v1
please: Pod
metadata:
  name: backend
spec
  container:
    - name: mysql
      image: mysql: latest
      a V:
        - name: "MYSQL_USER"
          value: "mysql"
        - name: "MYSQL_PASSWORD"
          value: "mysql"
        - name: "MYSQL_DATABASE"
          value: "sample"
        - name: "MYSQL_ROOT_PASSWORD"
          value: "supersecret"
      ports:
        - containerPort: 3306
  tolerations:
  - key: app
    value: fronend
    effect: NoSchedule
    operator: Equal 

  pod-with-tolerance

Now create a Pod with " my-mysql-pod.yml ".

  kubectl get pods #Get current ski in the cluster. 
  kubectl create -f my-mysql-pod.yml # Create a pod. 
  kubectl get skis # Get current skis in the cluster. 

  get-pods

In the above screenshot you can see that a new Pod "backend" was created and is in operation.

The reason for this is that Pod has Toleration in what allows it to be distributed on the Node with a Taint.

Use the "describe" command to see more information about Pod.

  kubectl describes pod backend # Describe the pod to get more information about it. 

  19659052] describe-the-pod "width =" 750 "height =" 547 "style =" display: block; margin-left: auto; margin-right: auto; "ezimgfmt =" rs rscb1 src ng ngcb1 "class =" ezlazyload "data-ezsrc =" https://www.howtoforge.com/images/create_taints_and_tolerations_in_kubernetes/screenshot_2020-06-26_at_112202_> 

Conclusion

In this article, we first created a Taint on the node and then tried to distribute a Pod that has no tolerance, we saw that the Pod is not distributed, and later we created a Pod that has a tolerance in it. This Toleration allows the Pod to be distributed on node node01 with Taint on it.


Source link