Create and use node pools with labels and taints
This document guides you through creating node pools using the KakaoCloud console, setting labels and taints for those pools, and effectively deploying workloads to the appropriate instance group based on specific conditions. Labels are used to differentiate and organize resources within the cluster, while taints and tolerations provide more granular control over workload scheduling.
- Estimated time: 10 minutes
- Region: kr-central-2
- Prerequisites
About this scenario
In this scenario, you'll create instance groups in a Kubernetes cluster and use them to deploy pods. The key steps are as follows:
-
Create node pools: Use the KakaoCloud console to create node pools and configure labels and taints for each pool.
-
Deploy pods based on labels and taints: Deploy pods that match the created node pools using NodeSelector based on labels and tolerations for taints.
Prework
In the prework step, you will set up the environment for the tutorial. Check the following to ensure your Kubernetes cluster environment is ready.
Create a Kubernetes cluster
Create a Kubernetes cluster using the KakaoCloud Kubernetes Engine. Follow the steps in Setting up Kubernetes cluster with Kubernetes Engine to create the environment.
Step 1. Create an instance group
-
In KakaoCloud Console > Kubernetes Engine > Cluster list, select the
tutorial
Kubernetes cluster created during prework. -
Select the Node Pool tab, and click the [Create node pool] button on the right. Use the table below to create a node pool with the label
label=true
.Category Item Settings/Inputs Node pool type Virtual Machine Basic settings Node Pool Name tutorial-label Instance Type t1i.micro Volume Type / Size SSD / 50GB Number of Nodes 2 Node pool network VPC tutorial Subnet Select all (default) Key pair User's Key Pair Advanced settings Node Label - Key: label
- Value: true -
Select the Node Pool tab, and click the [Create node pool] button on the right. Use the table below to create a node pool with the label
taint=true
and the tainttutorial=true:NoSchedule
.Category Item Settings/Inputs Node pool type Virtual Machine Basic settings Node Pool Name tutorial-taint Instance Type t1i.small Volume Type / Size SSD / 50GB Number of Nodes 2 Node pool network VPC tutorial Subnet Select all (default) Key pair User's Key Pair Advanced settings Node Label - Key: taint
- Value: trueNode Taint - Key: tutorial
- Value: true
- Taint Effect: NoSchedule
Step 2. Deploy pods using labels
In this step, you will set up pods to be scheduled only on nodes in the node pool that match the specified labels.
-
Write and deploy a YAML file that defines the pods, specifying a NodeSelector to schedule the pod to nodes with the
label=true
label.cat <<EOF | kubectl create -f-
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-pod-label-example
spec:
containers:
- name: ubuntu-container
image: ubuntu
command: ["/bin/bash"]
args: ["-c", "while true; do echo 'Event: Label Pod is Running...'; sleep 10; done"]
nodeSelector:
label: "true"
EOF -
Use the following command to verify that the pod was successfully created. The
ubuntu-pod-label-example
pod should be listed.kubectl get pod ubuntu-pod-label-example
-
Use the following command to verify that the pod has been assigned to a node with the
label=true
label. This command will show the name of the node where the pod is scheduled. Go to KakaoCloud Console > Kubernetes Engine > tutorial > Node Pool tab > tutorial-label > Node tab to check if the node matches.kubectl get pod ubuntu-pod-label-example -o custom-columns=NODE_NAME:.spec.nodeName
infoThe
tutorial-label
node pool of the cluster must be in a Running state to verify.- This process may take 5 to 7 minutes.
-
The created nodes have some default information set in their labels. Based on this information, you can place pods more precisely. Below is an example of deploying a pod to a node located in availability zone
kr-central-2-b
based on the previous example.cat <<EOF | kubectl create -f-
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-pod-label-az-b-example
spec:
containers:
- name: ubuntu-container
image: ubuntu
command: ["/bin/bash"]
args: ["-c", "while true; do echo 'Event: Label Pod is Running...'; sleep 10; done"]
nodeSelector:
label: "true"
topology.kubernetes.io/zone: "kr-central-2-b"
EOF -
Use the following command to verify that the pod has been successfully scheduled on a node in availability zone
kr-central-2-b
. Go to KakaoCloud Console > Kubernetes Engine > tutorial > Node Pool tab > tutorial-label > Node tab to check if the node matches and whether the availability zone of the node iskr-central-2-b
.kubectl get pod ubuntu-pod-label-az-b-example -o custom-columns=NODE_NAME:.spec.nodeName
Step 3. Deploy pods using taints and tolerations
In this step, you will deploy an example pod to the node pool that has the tutorial=true:NoSchedule
taint. This taint ensures that only pods with the appropriate toleration can be scheduled on that node.
-
Write and deploy a YAML file that defines the pod. This file includes the pod configuration and the toleration that matches the taint applied to the node pool.
cat <<EOF | kubectl create -f-
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-pod-toleration-example
spec:
containers:
- name: ubuntu-container
image: ubuntu
command: ["/bin/bash"]
args: ["-c", "while true; do echo 'Event: Tolerations Pod is Running...'; sleep 10; done"]
nodeSelector:
taint: "true"
tolerations:
- key: "tutorial"
operator: "Equal"
value: "true"
effect: "NoSchedule"
EOF -
Use the following command to verify that the pod was successfully created. The
ubuntu-pod-toleration-example
pod should be listed.kubectl get pod ubuntu-pod-toleration-example
-
Use the following command to verify that the pod has been assigned to a node with the taint. This command will show the name of the node where the pod is scheduled. Go to KakaoCloud Console > Kubernetes Engine > tutorial > Node Pool tab > tutorial-taint > Node tab to check if there is a matching node.
kubectl get pod ubuntu-pod-toleration-example -o custom-columns=NODE_NAME:.spec.nodeName