关于rancher中无法删除Machine的问题

环境信息:
RKE2 版本: v1.31.7+rke2r1

节点 CPU 架构,操作系统和版本:x86_64,rocky linux 8

集群配置:3 master 3etcd 8node

问题描述:

通过rancher更新rke2证书失败,导致集群状态异常,日志如下:

[INFO ] refreshing etcd restore state
2025-12-30 23:43:38
[INFO ] waiting for [custom-1fc3e9f7b3dd] certificate rotation
2025-12-30 23:43:52
[INFO ] starting [custom-581cabdb357c] certificate rotation
2025-12-30 23:43:54
[INFO ] waiting for [custom-581cabdb357c] certificate rotation
2025-12-31 14:30:50
[INFO ] waiting for [custom-ff7fa84697fb] certificate rotation
2025-12-31 14:40:27
[ERROR] operation [custom-581cabdb357c] certificate rotation failed

尝试过移除节点后重新将节点加入,但是无法移除节点导致无法安装rke2-agent,但是节点上面的agent应用已通过命令 rke2-uninstall.sh 卸载

通过 RKE2 commands - Rancher 2.x / RKE2 - Rancher 中文论坛进行安装,但是node无法恢复

重现步骤:

无法复现,没有查到证书更换的错误日志

修复步骤:
在rancher的资源中找到 Machine 资源通过node的名称查找对应资源,例如:
custom-581cabdb357c找到它并修改yaml文件,删除finalizers中的值并保存,集群将会删除这个资源

这时候检查对应集群的node信息将会发现,这个节点已经被移除当前集群

清理节点上面的agent并重新安装

移除agent节点需要注意并不是直接uninstall就可以,还需要注意以下几点:
1、清除etcd中的节点信息,一般可以通过kubectl get node查看不存在agent节点即为移除;
2、如果重新加入时 node-name没有变化,需要清除旧的agent的password

kubectl -n kube-system get secrets | grep node.k8s-agent-01.password

如果存在就要删除

kubectl -n kube-system delete secret node.k8s-agent-01.password

3、清理agent节点,uninstall后还要查看/etc/rancher/node和 /var/lib/rancher/rke2 是否还有残留

以上是我上个月清理agent节点重新加入的细节,希望能有帮助