Get AKS versions report using PowerShell

Hey Scripters! Today short post about gathering AKS versions report across all subscriptions in specific tenant.

Kubernetes community release new version basically every 3 months. Microsoft Azure Kubernetes Service must follow all upgrades and support only 3 latest minor version of Kubernetes.

It is done in following way :

  • The current minor version that is released in AKS (N)
  • Two previous minor versions. Each supported minor version also supports two stable patches.

This is known as “N-2”: (N (Latest release) – 2 (minor versions)).

Unfurtunately there is no PowerShell command to check supported version (but it’s possible using API) or you can simply check supported version using Azure CLI command

az aks get-versions --location westeurope --output table

Once you know supported version you can check which AKS instances will be not supported soon by using my script.

Script:

Param (
  [String] [Parameter(Mandatory)]$TenantId = ''
)

$subscriptionArray = Get-AzureRmSubscription -TenantId $TenantId
$AKSArrayInfo = @()

foreach ($sub in $subscriptionArray) {

    $SubscriptionID = $sub.id
    Select-AzureRMSubscription -SubscriptionId $SubscriptionID | Out-Null

    # Gather all AKS instnaces in subscription
    $AKSArray = Get-AzureRmResource | Where-Object ResourceType -eq "Microsoft.ContainerService/managedClusters"
    foreach ($AKS in $AKSArray) {

        $Path = Export-AzureRmResourceGroup -ResourceGroupName $Aks.ResourceGroupName
    
        $aksTemplate = Get-Content $Path.Path | ConvertFrom-Json
        $aksInfo = $aksTemplate.resources | where-object type -eq "Microsoft.ContainerService/managedClusters"
        $aksVersion = $aksInfo.properties.kubernetesVersion
    
        $AKSArrayInfo += New-Object PSObject -Property @{
            aksName                     = $aks.Name;
            aksResourceGroupName        = $aks.ResourceGroupName;
            subscritionId               = $subscriptionId;
            aksVersion                  = $aksVersion;
        }
            
     
        Remove-Item -Path $Path.Path
    }

}
$AKSArrayInfo

I hope it will be useful for some of you 😉

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.