Skip to main content

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.

Basic information

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:

  1. Create node pools: Use the KakaoCloud console to create node pools and configure labels and taints for each pool.

  2. 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

  1. In KakaoCloud Console > Kubernetes Engine > Cluster list, select the tutorial Kubernetes cluster created during prework.

  2. 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.

    CategoryItemSettings/Inputs
    Node pool typeVirtual Machine
    Basic settingsNode Pool Nametutorial-label
    Instance Typet1i.micro
    Volume Type / SizeSSD / 50GB
    Number of Nodes2
    Node pool networkVPCtutorial
    SubnetSelect all (default)
    Key pairUser's Key Pair
    Advanced settingsNode Label- Key: label
    - Value: true
  3. 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 taint tutorial=true:NoSchedule.

    CategoryItemSettings/Inputs
    Node pool typeVirtual Machine
    Basic settingsNode Pool Nametutorial-taint
    Instance Typet1i.small
    Volume Type / SizeSSD / 50GB
    Number of Nodes2
    Node pool networkVPCtutorial
    SubnetSelect all (default)
    Key pairUser's Key Pair
    Advanced settingsNode Label- Key: taint
    - Value: true
    Node 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.

  1. 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
  2. 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
  3. 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
    info

    The tutorial-label node pool of the cluster must be in a Running state to verify.

    • This process may take 5 to 7 minutes.
  4. 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
  5. 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 is kr-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.

  1. 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
  2. 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
  3. 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