Skip to content

Instantly share code, notes, and snippets.

@bakins
Created May 4, 2016 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakins/b636cf13d0a3c3d3928b39fa10fd983d to your computer and use it in GitHub Desktop.
Save bakins/b636cf13d0a3c3d3928b39fa10fd983d to your computer and use it in GitHub Desktop.
# get our hostip if running under kubernetes
if [[ -n "${KUBERNETES_NAMESPACE}" && -n "${KUBERNETES_PODNAME}" ]] ; then
KUBERNETES_HOSTIP=""
while true; do
KUBERNETES_HOSTIP=`kubectl get pods --namespace=${KUBERNETES_NAMESPACE} ${KUBERNETES_PODNAME} -o json | jq -r .status.hostIP`
if [ -n "${KUBERNETES_HOSTIP}" ] && [ "${KUBERNETES_HOSTIP}" != "null" ]; then
break
fi
sleep 1
done
export KUBERNETES_HOSTIP
KUBERNETES_NODENAME=`kubectl get pods --namespace=${KUBERNETES_NAMESPACE} ${KUBERNETES_PODNAME} -o json | jq -r .spec.nodeName`
export KUBERNETES_NODENAME
fi
# set statsd if not set
if [ -z "${STATSD_SERVER}" ]; then
# if running under kubernetes, we assume a statsd server is running on
# port 8125 on the host IP
if [ -n "${KUBERNETES_HOSTIP}" ]; then
STATSD_SERVER="${KUBERNETES_HOSTIP}:8125"
else
STATSD_SERVER=127.0.0.1:8125
fi
fi
export STATSD_SERVER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment