Created
July 19, 2019 08:31
-
-
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```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage