Skip to content

Instantly share code, notes, and snippets.

@voxxit
Created June 1, 2018 01:17
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 voxxit/746773d4636c9d9c8bf3af3675d321ea to your computer and use it in GitHub Desktop.
Save voxxit/746773d4636c9d9c8bf3af3675d321ea to your computer and use it in GitHub Desktop.
Short script to automatically register a new Kubernetes node with the ZeroTier One API
#!/bin/bash
set -e
[ -z ${ZT_API_TOKEN} ] && echo "Missing API token" && exit 1
[ -z ${ZT_NETWORK_ID} ] && echo "Missing network ID" && exit 1
which zerotier-cli # Check whether the zerotier-cli is installed...
if [ $? -ne 0 ]; then
curl -s 'https://pgp.mit.edu/pks/lookup?op=get&search=0x1657198823E52A61' | gpg --import && \
if z=$(curl -s 'https://install.zerotier.com/' | gpg); then echo "$z" | sudo bash; fi
fi
nodeID=$(sudo zerotier-cli info | awk '{print $3}')
# Send request to preauthorize this node on our network
curl \
-XPOST \
-H "Authorization: Bearer ${ZT_API_TOKEN}" \
-d "{\"name\":\"$(curl -s 169.254.169.254/latest/meta-data/instance-id)\",\"config\":{\"authorized\":true}}" \
"https://my.zerotier.com/api/network/${ZT_NETWORK_ID}/member/${nodeID}"
sleep 1
sudo zerotier-cli join ${ZT_NETWORK_ID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment