This message was deleted.
# general
a
This message was deleted.
a
I was doing it manually but then found this thread which was a much cleaner approach (this is assuming kubernetes is actually working) -> https://www.reddit.com/r/rancher/comments/18yf8bn/regarding_rke2_etcd_health_check/
pretty much from kubectl running from the cluster, run the following
for etcdpod in $(kubectl -n kube-system get pod -l component=etcd --no-headers -o custom-columns=NAME:.metadata.name); do kubectl -n kube-system exec $etcdpod -- sh -c "ETCDCTL_ENDPOINTS='<https://127.0.0.1:2379>' ETCDCTL_CACERT='/var/lib/rancher/rke2/server/tls/etcd/server-ca.crt' ETCDCTL_CERT='/var/lib/rancher/rke2/server/tls/etcd/server-client.crt' ETCDCTL_KEY='/var/lib/rancher/rke2/server/tls/etcd/server-client.key' ETCDCTL_API=3 etcdctl endpoint status"; done
pretty elegant, will execute the etcdctl command in each pod to get the status/health which tells you who is the leader
well sort of, might have to add another echo in the while loop so you can see which pod has the output
like this:
Copy code
for etcdpod in $(kubectl -n kube-system get pod -l component=etcd --no-headers -o custom-columns=NAME:.metadata.name); do echo $etcdpod; kubectl -n kube-system exec $etcdpod -- sh -c "ETCDCTL_ENDPOINTS='<https://127.0.0.1:2379>' ETCDCTL_CACERT='/var/lib/rancher/rke2/server/tls/etcd/server-ca.crt' ETCDCTL_CERT='/var/lib/rancher/rke2/server/tls/etcd/server-client.crt' ETCDCTL_KEY='/var/lib/rancher/rke2/server/tls/etcd/server-client.key' ETCDCTL_API=3 etcdctl endpoint status"; done
🏅 1
all credit to the person from that post
c
Wouaa cool. May I ask a subsidary question. If the leader server disappear, will K3s elect a new leader automatically ?
I will test out so I'll get my answer 🙂
@adorable-train-88202 Thanks a lot, I will test this, I think I don't have any etcd pod running in my k3S
I don't know if this is because I am using the Embedded etcd for K3s
Found it, using etcdctl on the host
Copy code
ETCDCTL_API=3 etcdctl --cacert=/scratchK3s/k3s/data/server/tls/etcd/server-ca.crt --cert=/scratchK3s/k3s/data/server/tls/etcd/client.crt --key=/scratchK3s/k3s/data/server/tls/etcd/client.key endpoint health --cluster --write-out=table

+----------------------------+--------+------------+-------+
|          ENDPOINT          | HEALTH |    TOOK    | ERROR |
+----------------------------+--------+------------+-------+
| <https://10.46.232.141:2379> |   true | 2.464256ms |       |
+----------------------------+--------+------------+-------+
a
ah nice, yeah I'm not too sure how that even looks like for K3s but the idea seemed the same
you try endpoint status vs endpoint health?
p
From your point i think i should look at "endpoint status"