Skip to content

Instantly share code, notes, and snippets.

@ivnilv
Forked from iocanel/get-host.ip.sh
Created October 17, 2023 20:21
Show Gist options
  • Save ivnilv/b2b4d634c3461f157fa072784adfd505 to your computer and use it in GitHub Desktop.
Save ivnilv/b2b4d634c3461f157fa072784adfd505 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