---
# System prepended metadata

title: rke2 worker 相同名稱註冊問題
tags: [trouble]

---

# rke2 worker 相同名稱註冊問題

* 情境: 如果想要刪除 w2 節點，並且在使用同一個節點名稱註冊會有以下問題。
```
rancher@w2:~> sudo journalctl -u rke2-agent.service
Aug 09 15:28:49 w2 rke2[2856]: time="2023-08-09T15:28:49+08:00" level=info msg="Waiting to retrieve agent configuration; server is not ready: Node password rejected, duplicate hostname or contents of '/etc/rancher/node/password' may not match server node-passwd entry, try enabling a unique node name with the --with-node-id flag"
Aug 09 15:28:54 w2 rke2[2856]: time="2023-08-09T15:28:54+08:00" level=info msg="Waiting to retrieve agent configuration; server is not ready: Node password rejected, duplicate hostname or contents of '/etc/rancher/node/password' may not match server node-passwd entry, try enabling a unique node name with the --with-node-id flag"
```

* 原因是因為 w2 註冊時用的 secret 還是使用同一個，因此 k8s 預設就會拿這個 secret 來做註冊，註冊就會有問題
```
rancher@m1:~> kubectl -n kube-system get secret
w1.node-password.rke2                                    Opaque               1      68d
w2.node-password.rke2                                    Opaque               1      68d
w3.node-password.rke2                                    Opaque               1      68d
```

* 把舊的 secret 刪掉後他就會自動產生一個現在 w2 註冊的 secret
```
rancher@m1:~> kubectl -n kube-system delete secrets w2.node-password.rke2
secret "w2.node-password.rke2" deleted

$ kubectl -n kube-system get secret
w1.node-password.rke2                                    Opaque               1      68d
w2.node-password.rke2                                    Opaque               1      14s
w3.node-password.rke2                                    Opaque               1      68d
```

* 最後就可以使用相同名稱順利註冊完成拉
```
rancher@m1:~> kubectl get nodes
NAME   STATUS   ROLES                       AGE   VERSION
m1     Ready    control-plane,etcd,master   68d   v1.26.6+rke2r1
m2     Ready    control-plane,etcd,master   68d   v1.26.6+rke2r1
m3     Ready    control-plane,etcd,master   68d   v1.26.6+rke2r1
w1     Ready    worker                      68d   v1.26.6+rke2r1
w2     Ready    worker                      18m   v1.26.6+rke2r1
w3     Ready    worker                      68d   v1.26.6+rke2r1
```

###### tags: `trouble`