Last active
June 5, 2025 05:08
-
-
Save sjwaight/c47c6fcbf8ee5dd739baf170b7e54deb to your computer and use it in GitHub Desktop.
Walk all AKS clusters in a single Azure subscription and disable auto-upgrade. This is to support adding clusters to an auto-upgrade in Fleet Manager. GitHub Copilot generated.
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
#!/bin/bash | |
# Set this to true if you want to actually perform the update | |
# Set to false for a dry run that just lists the clusters that would be updated | |
PERFORM_UPDATE=false | |
echo "Listing all AKS clusters in the subscription..." | |
# Get all AKS clusters in the subscription | |
clusters=$(az aks list --query "[].{name:name, resourceGroup:resourceGroup, autoUpgradeChannel:autoUpgradeChannel}" -o json) | |
# Count the total clusters | |
total_clusters=$(echo $clusters | jq '. | length') | |
echo "Found $total_clusters AKS clusters" | |
# Loop through all clusters | |
echo $clusters | jq -c '.[]' | while read -r cluster; do | |
name=$(echo $cluster | jq -r '.name') | |
resourceGroup=$(echo $cluster | jq -r '.resourceGroup') | |
autoUpgradeChannel=$(echo $cluster | jq -r '.autoUpgradeChannel') | |
echo "Cluster: $name in resource group: $resourceGroup" | |
echo " Current auto-upgrade channel: $autoUpgradeChannel" | |
# Only update if the auto-upgrade channel is not 'none' | |
if [ "$autoUpgradeChannel" != "none" ]; then | |
echo " This cluster has auto-upgrade enabled." | |
if [ "$PERFORM_UPDATE" = true ]; then | |
echo " Disabling auto-upgrade..." | |
az aks update --resource-group "$resourceGroup" --name "$name" --auto-upgrade-channel none | |
# Verify the update | |
updated_channel=$(az aks show --resource-group "$resourceGroup" --name "$name" --query "autoUpgradeChannel" -o tsv) | |
echo " Auto-upgrade channel has been set to: $updated_channel" | |
else | |
echo " [DRY RUN] Would disable auto-upgrade on this cluster." | |
fi | |
else | |
echo " Auto-upgrade is already disabled on this cluster." | |
fi | |
echo "-----------------------------------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment