Skip to content

Instantly share code, notes, and snippets.

@rmohta
Last active July 30, 2021 17:48
Show Gist options
  • Save rmohta/095c3868b5c30dc3d08bdc9e14eac289 to your computer and use it in GitHub Desktop.
Save rmohta/095c3868b5c30dc3d08bdc9e14eac289 to your computer and use it in GitHub Desktop.
Envoy: Get hostnames for configured clusters

When none of the CLI tools like istioctl or glooctl are available, use wget/curl | jq/grep to find all the hostnames configured in Envoy

Get clusters

Assuming Envoy admin port is 19000. Invoke below script to invoke Envoy admin API

$ cat collect-gloo-upstream.sh
#!/usr/bin/env sh
kubectl -n $1 exec -it $2  -- wget -O - http://127.0.0.1:19000/clusters?format=json

$ /bin/sh ./collect-gloo-upstream.sh ${my-ns} ${envoy-pod-name} > ${envoy-pod-name}-cluster.json

grep all hostnames

$ grep '"hostname": "' ${envoy-pod-name}-cluster.json
# Count number of hostnames
$ grep '"hostname": "' ${envoy-pod-name}-cluster.json | wc -l

jq to get all hostnames

Use grep to remove any 'null' hostname when host_statuses array is empty due to un-resolvable hostnames.

$ jq ".cluster_statuses[].host_statuses[]?.hostname" ${envoy-pod-name}-cluster.json | grep -v 'null'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment