delete_nodes.yaml is used to safely remove specified nodes from the cluster, including eviction and deletion of nodes from Kubernetes, etcd decommissioning, CRI uninstallation, and DNS cleanup.
-
Global Initialization
- Execute the
native/rootrole on all nodes. - Load the
defaultsrole on all nodes.
- Execute the
-
etcd Node Scaling Down (external mode only)
- For nodes in the
etcdgroup that need to be uninstalled, execute in sequence:etcd/prepareetcd/scaling_downetcd/postprocess
- Triggered only when
delete.etcdistrueand the node is in theneed_uninstall_etcdlist.
- For nodes in the
-
Ensure Control Plane Nodes Are Available
- Execute pre-checks on
kube_control_planenodes to ensure at least one control plane node remains after deletion. - Also execute
kubernetes/sync-etcd-configto sync etcd configuration to the remaining control plane nodes.
- Execute pre-checks on
-
Remove Node from Kubernetes Cluster
- For nodes in the
k8s_clustergroup to be deleted, execute pre-tasks:kubectl cordon: Prevent new Pods from being scheduled to the node.kubectl drain: Evict workloads from the node.- If using Calico, execute
calicoctl delete node. kubectl delete node: Delete the node from the cluster.
- Then execute:
uninstall/kubernetes: Uninstall Kubernetes components.uninstall/cri: Uninstall the container runtime (ifdelete.criis configured and the node does not belong to theimage_registrygroup).
- For nodes in the
-
Clean Local DNS Configuration
- Clean up locally-written hosts marker segments by KubeKey.
- Triggered only when
delete.dnsistrueand the node is in thedelete_nodeslist.
-
Uninstall etcd and Image Registry
- Execute the
etcdrole on corresponding nodes to uninstall etcd (ifdelete.etcdis enabled). - Execute
uninstall/image-registryonimage_registrynodes (ifdelete.image_registryis enabled).
- Execute the
- Before deleting a node, ensure that workloads on the node have been migrated or backed up.
- Deleting control plane nodes will trigger additional safety checks to prevent accidental deletion that could cause cluster loss of control.