Skip to content

Instantly share code, notes, and snippets.

@michelesr
Last active January 5, 2021 16:23
Show Gist options
  • Save michelesr/8c5bae9d840b00a1bcf7a4fdef7f0632 to your computer and use it in GitHub Desktop.
Save michelesr/8c5bae9d840b00a1bcf7a4fdef7f0632 to your computer and use it in GitHub Desktop.
Update EKS managed nodegroups
#!/usr/bin/env bash
set -eux
# used to process output with awk
export AWS_DEFAULT_OUTPUT=text
disable_cluster_autoscaler() {
# delete the tag from the autoscaling group
aws autoscaling delete-tags \
--tags ResourceId=$1,ResourceType=auto-scaling-group,Key=k8s.io/cluster-autoscaler/enabled
}
enable_cluster_autoscaler() {
# add the tag to the autoscaling group $1
aws autoscaling create-or-update-tags \
--tags ResourceId=$1,ResourceType=auto-scaling-group,Key=k8s.io/cluster-autoscaler/enabled,Value=true,PropagateAtLaunch=true
}
get_asg() {
# retrieve the autoscaling group associated with the managed nodegroup
aws autoscaling describe-tags --filters \
Name=value,Values=$1 \
Name=key,Values=eks:nodegroup-name | awk '{print $4}'
}
# retrieve all the nodegroups for the cluster
nodegroups=$(aws eks list-nodegroups --cluster-name ${CLUSTER_NAME} | awk '{print $2}')
for ng in ${nodegroups}; do
# retrieve the autoscaling group associated with the managed nodegroup
asg=$(get_asg ${ng})
aws eks wait cluster-active --name ${CLUSTER_NAME}
aws eks wait nodegroup-active --cluster-name ${CLUSTER_NAME} --nodegroup-name ${ng}
disable_cluster_autoscaler ${asg}
aws eks update-nodegroup-version --cluster-name ${CLUSTER_NAME} --nodegroup-name ${ng}
aws eks wait nodegroup-active --cluster-name ${CLUSTER_NAME} --nodegroup-name ${ng}
enable_cluster_autoscaler ${asg}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment