Skip to content

Instantly share code, notes, and snippets.

@chachan
Forked from iocanel/get-host.ip.sh
Created October 24, 2017 01:17
Show Gist options
  • Save chachan/a052883375ef804c0569eb485baae251 to your computer and use it in GitHub Desktop.
Save chachan/a052883375ef804c0569eb485baae251 to your computer and use it in GitHub Desktop.
Get the docker host ip inside Kubernetes
#!/bin/bash
KUBERNETES=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`
POD=`hostname`
curl -s -k -H "Authorization: Bearer $TOKEN" $KUBERNETES/api/v1/namespaces/$KUBERNETES_NAMESPACE/pods/$POD | grep -i hostIp | cut -d "\"" -f 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment