Last active
August 31, 2020 14:54
-
-
Save CermakM/d6822926ce53e9fef271f8a2b66f8631 to your computer and use it in GitHub Desktop.
etcdctl script to connect to etcd deployed by Kubespray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MEMBERS=$(\ | |
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}' \ | |
| tr " " "," | |
) | |
ETCD_PORT=${ETCD_PORT:-2379} | |
ENDPOINTS=() | |
{ | |
IFS=, read -a members <<< "$MEMBERS" | |
for m in "${members[@]}"; do | |
ENDPOINTS+="https://$m:$ETCD_PORT" | |
ENDPOINTS+="," | |
done | |
} | |
# --- | |
if [[ "${ETCDCTL_API}" -eq "2" ]]; then | |
ETCDCTL_API=2 etcdctl \ | |
--endpoints=${ENDPOINTS:0:${#ENDPOINTS}-1} \ | |
--ca-file /etc/ssl/etcd/ssl/ca.pem \ | |
--cert-file /etc/ssl/etcd/ssl/member-$(hostname).pem \ | |
--key-file /etc/ssl/etcd/ssl/member-$(hostname)-key.pem \ | |
"$@" | |
else | |
# default to ETCDCTL_API v3 instead of v2 | |
ETCDCTL_API=3 etcdctl \ | |
--endpoints=${ENDPOINTS:0:${#ENDPOINTS}-1} \ | |
--cacert=/etc/ssl/etcd/ssl/ca.pem \ | |
--cert=/etc/ssl/etcd/ssl/member-$(hostname).pem \ | |
--key=/etc/ssl/etcd/ssl/member-$(hostname)-key.pem \ | |
"$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment