Remove worker nodes#
The mkectl node remove command cordons off and drains the node targeted for
removal, removes that node from the MKE 4 cluster, runs k0s reset on the host,
cleans up various folders and files to remove any traces of k0s, and updates the
MkeConfig stored in the cluster to remove the node.
Note
The mkectl node remove command is idempotent, and thus running
it against hosts that are not part of the cluster is a no-op.
Conmand action sequence#
The worker node removal sequence for each host in the hosts.yaml configuration file is as follows:
-
Reachability check.
mkectlverifies SSH connectivity to the target host and to the cluster controller. -
Cluster state check.
The
mkectl node removecommand aborts if the MKE 4 cluster is not stable. All cluster nodes that are not currently in a transitioning state must be inReadystate. -
Components version check.
The
mkectl node removecommand aborts if the cluster was deployed with a differentmkectlbinary or if the cluster runs a different k0s version than the onemkectlsupports. -
Node state check.
mkectldetermines whether the node exists in the cluster and its health status, to decide which removal path to take. Refer to Node scenarios for the full matrix. -
Node state lock.
The node is marked as
removing. -
Cordon.
The node is marked unschedulable. No new workloads are scheduled on it.
-
Drain.
Workloads are evicted from the node. For that, the
kubectl draincommand is executed against it, run on a controller node:kubectl drain --force \ --grace-period=<seconds> \ --timeout=<duration> \ --delete-emptydir-data \ --ignore-daemonsets \ <node-name>Warning
If the drain operation fails, the error is reported and node removal continues. The node is still deleted from the cluster.
-
Delete node.
The node object is removed from the Kubernetes cluster.
-
Cleanup.
k0s resetis run on the host to remove MKE 4 artifacts. In addition, the command removes any lingering traces of k0s from various files and folders.Warning
If you receive an error indicating that the cleanup operation has failed, the node has already been removed from the cluster, however the host may require manual cleanup. To confirm, re-run
mkectl node remove. If the error persists, manual host cleanup is required. -
Cluster config patch.
The
MkeConfigstored in the cluster is updated to remove the node.
Examples: mkectl node remove#
| Command example | Description |
|---|---|
mkectl node remove --hosts-path hosts.yaml |
Remove nodes defined in the hosts.yaml configuration file. |
mkectl node remove --hosts-path hosts.yaml --timeout-minutes 20 |
Remove nodes with a custom total timeout of 20 minutes. |
mkectl node remove --hosts-path hosts.yaml\--drain-timeout-minutes 5 \--drain-grace-period-minutes 2.5 |
Remove nodes with a custom drain timeout of 5 minutes and a grace period of 2.5 minutes. |
mkectl node remove --hosts-path hosts.yaml --ssh-key ~/.ssh/prod-key.pem |
Remove nodes using an SSH key to connect to the cluster controller. |
mkectl node remove --hosts-path hosts.yaml\--ssh-key ~/.ssh/node-key.pem \--bastion-ssh-key ~/.ssh/bastion-key.pem |
Remove nodes when the controller is behind a bastion host. |