Skip to content

Instantly share code, notes, and snippets.

@eshleebien
Created July 19, 2019 08:31
Show Gist options
  • Select an option

  • Save eshleebien/208fe59213678c4e16257ecb76097b69 to your computer and use it in GitHub Desktop.

Select an option

Save eshleebien/208fe59213678c4e16257ecb76097b69 to your computer and use it in GitHub Desktop.
Label current node using Kubernetes API. Usage ```./kube-api-labeler.sh http://kube-api-server:8000 service_account_token```
SERVER=$1
HOSTNAME=`curl -s http://169.254.169.254/latest/meta-data/local-hostname`
TOKEN=$2
$KEY="node-role"
$VALUE="applications"
while true; do
if curl -s --insecure -k -H "Accept: application/json" -H "Authorization: Bearer $TOKEN" $SERVER/api/v1/nodes | grep $HOSTNAME
then
break
fi
echo "Waiting for this node to connect to the Kubernetes cluster in $SERVER"
sleep 10
done
curl --insecure -k -v -H "Accept: application/json" -H "Authorization: Bearer $TOKEN" -XPATCH -d '{"metadata":{"labels":{"$KEY":"$VALUE"}}}' -H "Content-Type: application/merge-patch+json" $SERVER/api/v1/nodes/$HOSTNAME
@eshleebien

Copy link
Copy Markdown
Author

Usage

$ ./kube-api-labeler.sh http://kube-api-server:8000 service_account_token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment