Removing worker nodes from a cluster

Remove worker nodes from a Kubernetes cluster that the installer created by lowering the worker count in bootstrap.env and running the scale-workers phase, which drains each node before it destroys the server.

Before you start, meet the following requirements:

  • The installer created the cluster with DEPLOY_INFRA set to true.
  • You run the installer from the working folder that created the cluster, which holds bootstrap.env and the .kubernetes-install folder.
  • INFRA_TERRAFORM_VARS_FILE is empty.
  • The installer image contains the scale-workers phase.

The phase removes the highest-numbered workers, and you cannot choose a different worker. At least one worker always remains, so a value of INFRA_WORKER_COUNT below 1 is refused, and a cluster with a single worker cannot be scaled down. To remove the last worker, destroy the cluster.

  1. Lower the worker count in bootstrap.env, for example, from 3 to 1.
    INFRA_WORKER_COUNT="1"

    In this example, the phase removes worker-3 and worker-2.

  2. List the Pods that run on each node that the phase removes.
    kubectl --kubeconfig .kubernetes-install/kubeconfig get pods -A -o wide \
      --field-selector spec.nodeName=<node-name>
  3. List the PodDisruptionBudgets that can block the drain.
    kubectl --kubeconfig .kubernetes-install/kubeconfig get pdb -A
  4. Run the scale-workers phase.
    docker run -it --rm \
      -v "$(pwd)":/config \
      --network host \
      container.repository.cloudera.com/cloudera/ccf-install:<TAG> \
      scale-workers

    The phase lists the workers that it removes and asks for confirmation. In a non-interactive run, add the --yes option, because the phase refuses to remove workers without a confirmation.

  5. Confirm the removal when the phase prompts you.

    You do not need to drain the nodes yourself. For each node, the phase drains the node, deletes the node from Kubernetes, and only then destroys the server with Terraform. The drain is graceful, so a PodDisruptionBudget or a Pod that cannot be rescheduled stops the run before the phase destroys anything.

  6. Verify that the removed nodes are gone and that their Pods run on the remaining workers.
    kubectl --kubeconfig .kubernetes-install/kubeconfig get nodes
    kubectl --kubeconfig .kubernetes-install/kubeconfig get pods -A -o wide
  7. Optional: On a cluster that has Cloudera Cloud Factory installed, verify that every PersistentVolumeClaim is Bound and that all Pods are Running.
    kubectl --kubeconfig .kubernetes-install/kubeconfig get pvc -A
    kubectl --kubeconfig .kubernetes-install/kubeconfig get pods -A

The cluster has the number of workers that INFRA_WORKER_COUNT specifies, and nodes.json no longer lists the removed workers. The numbers of the removed workers are not reused.

If the run stops, the phase leaves the cluster in a state that you can retry by running the phase again. For more information, see Removing a worker node stops because the drain is blocked and Terraform fails to destroy a server after a worker node is removed.