Create and use node pools with labels and taints
This document guides you through creating a node pool in Kakao Cloud Console, setting labels and taints, and deploying workloads to appropriate instance groups.
- Estimated time: 10 minutes
- User environment
- Region: kr-central-2
- Prerequisites
About this scenario
In this scenario, you will create an instance group in the Kubernetes cluster and use it to deploy pods. This includes using labels and taints to effectively deploy workloads to the appropriate instance group based on specific conditions. Labels are used to distinguish and organize resources within the cluster, while taints and tolerations allow finer control over workload scheduling.
The main steps are as follows:
- Create node pool: Create a node pool using Kakao Cloud Console, setting appropriate labels and taints for each node pool.
- Deploy pods based on labels and taints: Deploy pods to the created node pools with configurations including NodeSelector based on labels and tolerations for taints.
Before you start
To follow this tutorial, you will need a Kubernetes environment. If you don't have an appropriate Kubernetes environment set up, refer to the Build Kubernetes Cluster with Kubernetes Engine tutorial to set up your environment.
Getting started
Step 1. Create instance group
-
Go to Kakao Cloud Console > Container Pack > Kubernetes Engine > Cluster List, and select the
tutorial
Kubernetes cluster created in the previous step. -
Select the Node Pool tab and click the [Create Node Pool] button. Follow the table below to create a node pool with the label
label=true
.Category Item Settings/Input Values Node pool type Virtual Machine Basic settings Node Pool Name tutorial-label Instance Type t1i.micro Volume Type/Size SSD / 50GB Node Count 2 Node pool network settings 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 again and click the [Create Node Pool] button. Follow the table below to create a node pool with the label
taint=true
and tainttutorial=true:NoSchedule
.Category Item Settings/Input Values Node pool type Virtual Machine Basic settings Node Pool Name tutorial-taint Instance Type t1i.small Volume Type/Size SSD / 50GB Node Count 2 Node pool network settings 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 configure pods to be scheduled only on nodes of the node pool based on labels.
-
Write and deploy a YAML file defining the pod. This file includes the pod configuration and a NodeSelector setting that ensures the pod will be deployed only on 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 has been created successfully. 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 to which the pod is assigned. Go to Kakao Cloud Console > Kubernetes Engine > tutorial > Node Pool tab > tutorial-label > Node tab and check if there is a matching node.kubectl get pod ubuntu-pod-label-example -o custom-columns=NODE_NAME:.spec.nodeName
The tutorial-label
node pool in the cluster should be in the Running
state for verification.
- This process may take 5 to 7 minutes.
-
The created nodes have some default information set in the labels. You can use this information to place pods more precisely. Below is an example based on the previous one, showing how to place pods on nodes located in the availability zone
kr-central-2-b
.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 correctly placed on a node in the availability zone
kr-central-2-b
. Go to Kakao Cloud Console > Kubernetes Engine > tutorial > Node Pool tab > tutorial-label > Node tab and check if there is a matching node and whether the availability zone of that node matcheskr-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 a node pool with the tutorial=true:NoSchedule
taint. This taint ensures that only pods with the appropriate toleration will be scheduled on those nodes.
-
Write and deploy a YAML file defining the pod. This file includes the pod configuration and a toleration that matches the taint on 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 has been created successfully. 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 to which the pod is assigned. Go to Kakao Cloud Console > Kubernetes Engine > tutorial > Node Pool tab > tutorial-taint > Node tab and check if there is a matching node.
kubectl get pod ubuntu-pod-toleration-example -o custom-columns=NODE_NAME:.spec.nodeName