This repository shows how we can configure different pods/deployments to be executed in specific nodes based on taints and tolerations.
In this case we have 3 different types of nodes:
- Public node (Any pod is able to be executed here)
- Private node (Only database related pods should be allowed to be executed here)
- Critical node (Only critical pods are supposed to be executed here)
To create these different node we make use of kind, which allows for an easier way to create clusters and nodes.
The following command creates the different nodes with corresponding labels in order to identify them.
kind create cluster --config kind-cluster.yaml -n taint-cluster
The kind-cluster.yaml file contains the configurations necessary to set labels to the different worker nodes to identify them. This is useful for monitoring and later on applying any taints or specific configurations to the node.
To apply the taints run the apply-taints.sh file, inside you will find 2 kubectl commands that filter by the name tag given in the kind-cluster.yaml.
With the following commands we can examine the configurations of the nodes to verify the taints and labels:
kubectl cluster-info --context kind-taint-cluster: Shows general data.kubectl get nodes --name=taint-cluster: Obtains the nodes that are being executed, to make sure all of them were created.kubectl describe node <node-name>: Obtains the specific node data.
Creating a pod is very straight forward. Just execute the following command:
kubectl apply -f nginx-pod.yaml
The nginx-pod.yaml file does not contain any toleration or nodeSelector so it will end up being created in the node with the label name=public-node.
Both of the deployments contain tolerations, this allows them to be created in nodes that have taints on them.
The postgres.yaml file contains the configuration necessary for the pod to be created ONLY in nodes that contain the taint key=data-storage:NoSchedule.
To create the Deployment run the following command: kubectl apply -f postgres.yaml
The httpd.yaml file contains the configuration necessary for the pod to be created ONLY in nodes that contain the taint key=critical-app:NoSchedule and nodes with the label name=critical-node.
To create the Deployment run the following command: kubectl apply -f postgres.yaml
Execute kubectl get pods -o wide to see in which node the pods are being created.