Skip to content

Instantly share code, notes, and snippets.

@jkfran
Created November 4, 2024 13:59
Show Gist options
  • Save jkfran/3e1ef521ad75ebfb6079a6304d24fc60 to your computer and use it in GitHub Desktop.
Save jkfran/3e1ef521ad75ebfb6079a6304d24fc60 to your computer and use it in GitHub Desktop.
This Bash script retrieves all Azure Kubernetes Service (AKS) clusters in your subscription and lists their associated outbound IP addresses. It helps in auditing and monitoring the outbound IP configurations for your AKS clusters.
#!/bin/bash
az aks list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o tsv | while IFS=$'\t' read -r name rg; do
# Check if both name and resource group are non-empty
if [[ -n "$name" && -n "$rg" ]]; then
ip_ids=$(az aks show --resource-group "$rg" --name "$name" --query 'networkProfile.loadBalancerProfile.effectiveOutboundIPs[].id' -o tsv)
# Check if ip_ids is non-empty
if [[ -n "$ip_ids" ]]; then
for ip_id in $ip_ids; do
ip=$(az network public-ip show --ids "$ip_id" --query ipAddress -o tsv)
echo "$name $rg $ip"
done
else
echo "No outbound IPs configured for cluster $name in resource group $rg"
fi
else
echo "Error: Could not retrieve name or resource group for one of the clusters."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment