get_etcd_info.sh 684 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. set -e # Exit immediately if a command exits with a non-zero status.
  3. instance_name=$1
  4. # Define the etcdctl command with endpoints option
  5. etcdctl_cmd="etcdctl endpoint status -w table --endpoints"
  6. # Get the ip of all the etcd pods with the specified labels
  7. etcd_pods=$(kubectl get pods -l app.kubernetes.io/name=etcd,app.kubernetes.io/instance=${instance_name} -o jsonpath='{.items[*].status.podIP}')
  8. # Check if the etcd pods are running
  9. if [ -z "$etcd_pods" ]; then
  10. echo "No etcd pods found"
  11. exit 1
  12. fi
  13. # Loop through the list of etcd pods and get their status
  14. endpoints=""
  15. for pod in $etcd_pods
  16. do
  17. endpoints+="$pod:2379,"
  18. done
  19. $etcdctl_cmd ${endpoints::-1}