Draining or Cordoning a Node

Last updated: 2021-08-17 15:32:42

    Operation Scenario

    This document explains how to drain or cordon a node.


    Cordoning a Node

    After a node is cordoned, new Pods cannot be scheduled to it, and if you want to schedule new Pods to it, you will need to manually uncordon it. There are two ways to cordon a node:

    • When creating a node, on the "CVM configuration" page, click Advanced settings and select "Enable cordoning".

    Uncordoning a Node

    After a node is uncordoned, new Pods can be scheduled to it. There are two ways to uncordon a node:

    When you create a node by running a script, you can uncordon it by adding a command for uncordoning the node in the script. Below is an example:

    # your initialization script
    echo "hello world!"
    # If you set unschedulable when you create a node, 
    # after executing your initialization script, 
    # use the following command to make the node schedulable.
    node=`ps -ef|grep kubelet|grep -oE 'hostname-override=\S+'|cut -d"=" -f2`
    #echo ${node}
    kubectl uncordon ${node} --kubeconfig=/root/.kube/config

    The kubectl uncordon command indicates uncordoning the node.

    Draining a Node


    Before performing maintenance on a node, you can safely evict a Pod from a node by draining the node. After the node is drained, all Pods (excluding those managed by DaemonSet) in the node will be automatically evicted to other nodes in the cluster, and the drained node will be set to cordoned status.


    For locally stored Pods, data will be lost after they are evicted. Please be cautious when doing so.


    1. Log in to the TKE console.
    2. In the left sidebar, click Clusters to go to the cluster management page.
    3. Click the ID/name of the cluster where node needs to be drained to enter the cluster management page. See the figure below:
    4. In the left sidebar, select "Node Management" > "Nodes" to go to the "Node list" page.
    5. In the row of the node to be drained, click More > Drain. See the figure below:
    6. In the pop-up dialog box, click OK to complete the draining.