This section describes how to use KubeKey to safely remove specified nodes from a Kubernetes cluster, including evicting and deleting nodes from Kubernetes, cleaning up etcd members, uninstalling the container runtime, and cleaning up DNS configuration.
- An existing Kubernetes cluster deployed by KubeKey.
- Ensure that workloads on the nodes to be deleted have been migrated or backed up.
- When deleting control plane nodes, ensure that at least one available control plane node remains in the cluster.
Note: Web Installer does not currently support deleting cluster nodes. Please use the command line instead.
If the cluster was installed via the Web Installer, you can retrieve the current cluster configuration files as follows.
cp kubekey/runtime/kubekey.kubesphere.io/v1/inventories/default/default.yaml kkv4-inventory.yamlcat schema/config.json | jq '{spec: .["kubernetes.json"]}' > kkv4-config.jsonExecute the following command to delete the specified nodes:
./kk delete nodes node1 node2 -i inventory.yaml -c config.yamlWhere node1 node2 are the names of the nodes to be deleted, which must match the host names defined in inventory.yaml.
KubeKey will perform the following operations in sequence:
- If the node belongs to the etcd cluster and
--allor related deletion options are configured, the etcd member will be removed first. - For Kubernetes nodes, execute
cordonto prevent new Pod scheduling anddrainto evict existing workloads. - If Calico is used, execute
calicoctl delete nodeto clean up network resources. - Delete the node from the Kubernetes cluster.
- Uninstall Kubernetes components and the container runtime (according to configuration).
- Clean up local DNS hosts configuration (according to configuration).
| Parameter | Description |
|---|---|
-i, --inventory |
Path to the inventory file defining node connection information |
-c, --config |
Path to the config file defining key cluster configuration |
--with-kubernetes |
Specifies the Kubernetes version |
--all |
Deletes all cluster components, including cri, etcd, dns, and image_registry |
--with-data |
Also deletes data directories (e.g., harbor data, registry data). Use with caution. |
--override |
Removes the deleted nodes from inventory.yaml after successful execution |
-a, --artifact |
Path to the offline package, used in air-gapped environments |
- Workload Migration: Before deleting nodes, ensure that workloads on the nodes have been migrated or backed up to avoid data loss.
- Control Plane Nodes: Deleting control plane nodes triggers additional safety checks to prevent accidental deletion from causing cluster failure. Be sure to ensure that at least one available control plane node remains after deletion.
- etcd Node Scaling Down: When using external etcd mode, ensure that the remaining etcd member count is odd after deleting etcd nodes to maintain cluster high availability.