RKE/RKE2 配置使用 etcdctl

etcdctl 工具需要配置 Endpoint 和证书路径才能正常使用,在此提供 RKE/RKE2 快速配置方法。

RKE

RKE 可以直接在 etcd 容器里使用:

1
2
3
4
5
6
root@docker-test-1:~# docker exec -it etcd etcdctl member list -w table
+------------------+---------+--------------------+----------------------------+----------------------------+------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
+------------------+---------+--------------------+----------------------------+----------------------------+------------+
| bad772e39a877329 | started | etcd-docker-test-1 | https://172.16.16.143:2380 | https://172.16.16.143:2379 | false |
+------------------+---------+--------------------+----------------------------+----------------------------+------------+

RKE2

获取 etcdctl 工具:

1
cp "$(find / -name etcdctl 2>/dev/null | grep -v snapshot | head -n1)" /usr/local/bin/

配置环境变量:

1
2
3
4
5
6
export ETCDCTL_ENDPOINTS=$(kubectl get nodes -o wide \
| awk '/etcd|control-plane/ {ips[$6]=1} END {for (ip in ips) printf "https://%s:2379,", ip}' \
| sed 's/,$//') && \
export ETCDCTL_CACERT=/var/lib/rancher/rke2/server/tls/etcd/server-ca.crt && \
export ETCDCTL_CERT=/var/lib/rancher/rke2/server/tls/etcd/server-client.crt && \
export ETCDCTL_KEY=/var/lib/rancher/rke2/server/tls/etcd/server-client.key

测试是否可以使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@rke2-cilium-01:~# etcdctl member list -w table
+------------------+---------+-------------------------+----------------------------+----------------------------+------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER |
+------------------+---------+-------------------------+----------------------------+----------------------------+------------+
| 5718964703a827e4 | started | rke2-cilium-02-4b910ae0 | https://172.16.16.121:2380 | https://172.16.16.121:2379 | false |
| 9c018be6510f17c0 | started | rke2-cilium-01-1d4e15f8 | https://172.16.16.120:2380 | https://172.16.16.120:2379 | false |
| f8c600993bbd4a2c | started | rke2-cilium-03-9d26e468 | https://172.16.16.122:2380 | https://172.16.16.122:2379 | false |
+------------------+---------+-------------------------+----------------------------+----------------------------+------------+
root@rke2-cilium-01:~# etcdctl endpoint status -w table
+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://172.16.16.120:2379 | 9c018be6510f17c0 | 3.5.21 | 61 MB | true | false | 42 | 117960820 | 117960820 | |
| https://172.16.16.121:2379 | 5718964703a827e4 | 3.5.21 | 62 MB | false | false | 42 | 117960820 | 117960820 | |
| https://172.16.16.122:2379 | f8c600993bbd4a2c | 3.5.21 | 64 MB | false | false | 42 | 117960820 | 117960820 | |
+----------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
Author

Warner Chen

Posted on

2025-07-29

Updated on

2025-07-29

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.