Skip to main content

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.

Note

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:

  1. Create node pool: Create a node pool using Kakao Cloud Console, setting appropriate labels and taints for each node pool.
  2. 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

  1. Go to Kakao Cloud Console > Container Pack > Kubernetes Engine > Cluster List, and select the tutorial Kubernetes cluster created in the previous step.

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

    CategoryItemSettings/Input Values
    Node pool typeVirtual Machine
    Basic settingsNode Pool Nametutorial-label
    Instance Typet1i.micro
    Volume Type/SizeSSD / 50GB
    Node Count2
    Node pool network settingsVPCtutorial
    SubnetSelect all (default)
    Key pairUser's key pair
    Advanced settingsNode Label- Key: label
    - Value: true
  3. 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 taint tutorial=true:NoSchedule.

    CategoryItemSettings/Input Values
    Node pool typeVirtual Machine
    Basic settingsNode Pool Nametutorial-taint
    Instance Typet1i.small
    Volume Type/SizeSSD / 50GB
    Node Count2
    Node pool network settingsVPCtutorial
    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 configure pods to be scheduled only on nodes of the node pool based on labels.

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

The tutorial-label node pool in the cluster should be in the Running state for verification.

  • This process may take 5 to 7 minutes.
  1. 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
  2. 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 matches 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 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.

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