Skip to content

Instantly share code, notes, and snippets.

@superseb
Last active April 13, 2023 07:06
Show Gist options
  • Save superseb/d27253befe5e180334162c18187212fb to your computer and use it in GitHub Desktop.
Save superseb/d27253befe5e180334162c18187212fb to your computer and use it in GitHub Desktop.
Rancher 2.x single install embedded etcd query

Rancher single install embedded etcd query

Rancher 2.6.3 and higher

docker exec -ti $(docker ps | grep -E "rancher/rancher:|rancher/rancher " | awk '{ print $1 }') bash -c "ETCDCTL_API=3 ETCDCTL_ENDPOINTS='https://127.0.0.1:2379' ETCDCTL_CACERT='/var/lib/rancher/k3s/server/tls/etcd/server-ca.crt' ETCDCTL_CERT='/var/lib/rancher/k3s/server/tls/etcd/server-client.crt' ETCDCTL_KEY='/var/lib/rancher/k3s/server/tls/etcd/server-client.key' etcdctl get / --prefix --keys-only"

Rancher 2.5 and higher

embedded etcdctl

docker exec $(docker ps | grep -E "rancher/rancher:|rancher/rancher |rancher/rancher@|rancher_rancher" | awk '{ print $1 }') etcdctl get / --prefix --keys-only

Rancher 2.2/2.3/2.4

Option 1: run etcd image matching the embedded version and re-use container network to use etcdctl

docker run -e ETCDCTL_API=3 --net=container:$(docker ps | grep -E "rancher/rancher:|rancher/rancher |rancher/rancher@|rancher_rancher" | awk '{ print $1 }') quay.io/coreos/etcd:v$(docker exec $(docker ps | grep -E "rancher/rancher:|rancher/rancher |rancher/rancher@|rancher_rancher" | awk '{ print $1 }') curl -s http://localhost:2379/version | docker run -i oildex/jq:1.6 jq -r .etcdserver) etcdctl get / --prefix --keys-only

Option 2: use curl to talk to the embedded etcd and decode using jq

etcd 3.3.x (Rancher 2.3.x)

docker exec $(docker ps | grep -E "rancher/rancher:|rancher/rancher |rancher/rancher@|rancher_rancher" | awk '{ print $1 }') curl -s -X POST -d '{"key": "AA==", "range_end": "AA=="}' http://localhost:2379/v3alpha/kv/range  | docker run -i oildex/jq:1.6 jq -r '.kvs[].key | @base64d'

etcd 3.4.x (Rancher 2.4.x/Rancher v2.5.x)

docker exec $(docker ps | grep -E "rancher/rancher:|rancher/rancher |rancher/rancher@|rancher_rancher" | awk '{ print $1 }') curl -s -X POST -d '{"key": "AA==", "range_end": "AA=="}' http://localhost:2379/v3/kv/range  | docker run -i oildex/jq:1.6 jq -r '.kvs[].key | @base64d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment