Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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