Skip to content

Instantly share code, notes, and snippets.

@goblain
Created December 9, 2016 09:48
Show Gist options
  • Save goblain/d8a2a1c557988040f453c7cd296d5a3c to your computer and use it in GitHub Desktop.
Save goblain/d8a2a1c557988040f453c7cd296d5a3c to your computer and use it in GitHub Desktop.
bash script to fetch service endpoints list as comma separated string from kubernetes api
# bash script to fetch service endpoints list as comma separated string from kubernetes api
# example will list kube-dns endpoints
export NAMESPACE=kube-system
export SERVICE=kube-dns
curl -s --header "Authorization: Bearer `cat /var/run/secrets/kubernetes.io/serviceaccount/token`" -k https://kubernetes.default/api/v1/namespaces/$NAMESPACE/endpoints/$SERVICE | jq '.subsets | map(.addresses) | reduce .[] as $item ([];. + $item) | map(.ip) | join(",")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment