Skip to content

Instantly share code, notes, and snippets.

@jchauncey
Created June 5, 2016 06:55
Show Gist options
  • Save jchauncey/8c1534681a8eab0c746f39b2143a3a0c to your computer and use it in GitHub Desktop.
Save jchauncey/8c1534681a8eab0c746f39b2143a3a0c to your computer and use it in GitHub Desktop.
get pod ips from kubernetes
export GET_PODS_URL=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/namespaces/$POD_NAMESPACE/pods
pod_names=$(curl -s $GET_PODS_URL --header "Authorization: Bearer $TOKEN" --insecure | jq --raw-output '.items[].metadata.name' | grep deis-nsqlookupd)
while read -r pod; do
GET_POD_URL=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/namespaces/$POD_NAMESPACE/pods/${pod}
pod_ip=$(curl -s $GET_POD_URL --header "Authorization: Bearer $TOKEN" --insecure | jq --raw-output '.status.podIP')
export LOOKUP_COMMAND="$LOOKUP_COMMAND -lookupd-tcp-address ${pod_ip}:4161"
done <<< "$pod_names"
exec nsqd -broadcast-address ${NODE_NAME} ${LOOKUP_COMMAND}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment