Skip to content

Commit c0698aa

Browse files
committed
import code snippet for blog post using gists
1 parent 6f39c7e commit c0698aa

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed

content/posts/embedded-etcd.md

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,7 @@ Unlike RKE2, k3s does not provide with `etcdctl` client binary during installati
1616

1717
Save the following shell script in a file called `get-etcdctl.sh` on the control plane nodes
1818

19-
```sh
20-
#!/usr/bin/env bash
21-
set -euo pipefail
22-
23-
# k3s etcd cert/key paths
24-
K3S_ETCD_CACERT="/var/lib/rancher/k3s/server/tls/etcd/server-ca.crt"
25-
K3S_ETCD_CERT="/var/lib/rancher/k3s/server/tls/etcd/server-client.crt"
26-
K3S_ETCD_KEY="/var/lib/rancher/k3s/server/tls/etcd/server-client.key"
27-
28-
# Check if certs exist
29-
if [[ ! -f "$K3S_ETCD_CACERT" || ! -f "$K3S_ETCD_CERT" || ! -f "$K3S_ETCD_KEY" ]]; then
30-
echo "❌ This host does not appear to be a k3s control plane node with embedded etcd."
31-
echo "Missing one or more of:"
32-
echo " $K3S_ETCD_CACERT"
33-
echo " $K3S_ETCD_CERT"
34-
echo " $K3S_ETCD_KEY"
35-
exit 1
36-
fi
37-
38-
# Get latest etcd version
39-
ETCD_VER=$(curl -s https://api.github.com/repos/etcd-io/etcd/releases/latest \
40-
| grep tag_name \
41-
| cut -d '"' -f4)
42-
43-
DOWNLOAD_URL="https://storage.googleapis.com/etcd"
44-
TAR_FILE="/tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz"
45-
46-
echo "📥 Downloading etcdctl ${ETCD_VER}..."
47-
curl -sSL "${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz" -o "${TAR_FILE}"
48-
49-
echo "📦 Extracting etcdctl to ${PWD}..."
50-
tar xzf "${TAR_FILE}" --strip-components=1 -C "${PWD}" etcd-${ETCD_VER}-linux-amd64/etcdctl
51-
rm -f "${TAR_FILE}"
52-
53-
chmod +x "${PWD}/etcdctl"
54-
55-
# Export k3s etcd environment vars
56-
export ETCDCTL_ENDPOINTS="https://[::1]:2379"
57-
export ETCDCTL_CACERT="$K3S_ETCD_CACERT"
58-
export ETCDCTL_CERT="$K3S_ETCD_CERT"
59-
export ETCDCTL_KEY="$K3S_ETCD_KEY"
60-
61-
echo "✅ etcdctl ${ETCD_VER} is ready in ${PWD}"
62-
echo "Example usage:"
63-
echo " ./etcdctl endpoint status --write-out=table"
64-
./etcdctl version
65-
66-
```
19+
{{< gist "netops2devops" "ce77206bedca137927c1e1cdbc386a65" >}}
6720

6821
## 2. Run the script
6922

0 commit comments

Comments
 (0)