How to use the command 'az aks' (with examples)

How to use the command 'az aks' (with examples)

The ‘az aks’ command is part of the Azure CLI (az) and is used to manage Azure Kubernetes Service (AKS) clusters. AKS simplifies the deployment, management, and scaling of containerized applications using Kubernetes.

Use case 1: List AKS clusters

Code:

az aks list --resource-group resource_group

Motivation: This use case is useful for retrieving a list of AKS clusters within a specified resource group. It allows users to quickly view all the AKS clusters they have deployed in their Azure environment.

Explanation:

  • list: Sub-command used to list AKS clusters.
  • --resource-group: Specifies the resource group that contains the AKS clusters.

Example output:

[
  {
    "id": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.ContainerService/managedClusters/<aks_cluster>",
    "name": "<aks_cluster>",
    "location": "<location>",
    "dns_prefix": "<dns_prefix>",
    "fqdn": "<fqdn>",
    "type": "Microsoft.ContainerService/ManagedClusters",
    "tags": {},
    "sku": {
      "name": "Basic"
    },
    "kubernetes_version": "1.21.1",
    "private_fqdn": "",
    "provisioning_state": "Succeeded",
    "agent_pool_profiles": [
      {
        "name": "nodepool1",
        "count": 3,
        "vmSize": "Standard_DS2_v2",
        "osType": "Linux",
        "osDiskSizeGB": 30,
        "osDiskType": "Managed"
      }
    ],
    "linux_profile": null,
    "windows_profile": null,
    "addon_profiles": {},
    "identity": null
  }
]

Use case 2: Create a new AKS cluster

Code:

az aks create --resource-group resource_group --name name --node-count count --node-vm-size size

Motivation: Creating a new AKS cluster is a common task when deploying and managing containerized applications. This use case allows users to easily create a new AKS cluster with the specified resource group, name, node count, and node virtual machine size.

Explanation:

  • create: Sub-command used to create a new AKS cluster.
  • --resource-group: Specifies the resource group in which the AKS cluster will be created.
  • --name: Specifies the name of the AKS cluster.
  • --node-count: Specifies the number of nodes in the AKS cluster.
  • --node-vm-size: Specifies the size of the virtual machines for the AKS cluster nodes.

Example output:

{
  "id": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.ContainerService/managedClusters/<aks_cluster>",
  "name": "<aks_cluster>",
  "location": "<location>",
  "dns_prefix": "<dns_prefix>",
  "fqdn": "<fqdn>",
  "type": "Microsoft.ContainerService/ManagedClusters",
  "tags": {},
  "sku": {
    "name": "Basic"
  },
  "kubernetes_version": "1.21.1",
  "private_fqdn": "",
  "provisioning_state": "Succeeded",
  "agent_pool_profiles": [
    {
      "name": "nodepool1",
      "count": 3,
      "vmSize": "Standard_DS2_v2",
      "osType": "Linux",
      "osDiskSizeGB": 30,
      "osDiskType": "Managed"
    }
  ],
  "linux_profile": null,
  "windows_profile": null,
  "addon_profiles": {},
  "identity": null
}

Use case 3: Delete an AKS cluster

Code:

az aks delete --resource-group resource_group --name name

Motivation: Sometimes it is necessary to delete an AKS cluster to free up resources or to decommission an application. This use case allows users to easily delete an AKS cluster by specifying the resource group and name of the cluster.

Explanation:

  • delete: Sub-command used to delete an AKS cluster.
  • --resource-group: Specifies the resource group that contains the AKS cluster to be deleted.
  • --name: Specifies the name of the AKS cluster to be deleted.

Example output:

{
  "id": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.ContainerService/managedClusters/<aks_cluster>",
  "name": "<aks_cluster>",
  "location": "<location>",
  "dns_prefix": "<dns_prefix>",
  "fqdn": "<fqdn>",
  "type": "Microsoft.ContainerService/ManagedClusters",
  "tags": {},
  "sku": {
    "name": "Basic"
  },
  "kubernetes_version": "1.21.1",
  "private_fqdn": "",
  "provisioning_state": "Deleting",
  "agent_pool_profiles": [
    {
      "name": "nodepool1",
      "count": 3,
      "vmSize": "Standard_DS2_v2",
      "osType": "Linux",
      "osDiskSizeGB": 30,
      "osDiskType": "Managed"
    }
  ],
  "linux_profile": null,
  "windows_profile": null,
  "addon_profiles": {},
  "identity": null
}

Use case 4: Get the access credentials for an AKS cluster

Code:

az aks get-credentials --resource-group resource_group --name name

Motivation: To interact with an AKS cluster, it is necessary to authenticate and obtain access credentials. This use case allows users to easily retrieve the access credentials for an AKS cluster by specifying the resource group and name.

Explanation:

  • get-credentials: Sub-command used to retrieve access credentials for an AKS cluster.
  • --resource-group: Specifies the resource group that contains the AKS cluster.
  • --name: Specifies the name of the AKS cluster.

Example output:

Merged "aks_cluster" as current context in ~/.kube/config

Use case 5: Get the upgrade versions available for an AKS cluster

Code:

az aks get-upgrades --resource-group resource_group --name name

Motivation: Keeping AKS clusters up-to-date with the latest versions of Kubernetes is important for security, performance, and feature updates. This use case allows users to easily retrieve the upgrade versions available for an AKS cluster by specifying the resource group and name.

Explanation:

  • get-upgrades: Sub-command used to retrieve the upgrade versions available for an AKS cluster.
  • --resource-group: Specifies the resource group that contains the AKS cluster.
  • --name: Specifies the name of the AKS cluster.

Example output:

{
  "controlPlaneProfile": {
    "upgrades": [
      {
        "kubernetesVersion": "1.21.2",
        "isPreview": false
      }
    ]
  },
  "agentPoolProfiles": [
    {
      "name": "nodepool1",
      "upgrades": [
        {
          "kubernetesVersion": "1.19.11",
          "isPreview": false
        },
        {
          "kubernetesVersion": "1.20.9",
          "isPreview": false
        },
        {
          "kubernetesVersion": "1.21.2",
          "isPreview": false
        }
      ]
    }
  ]
}

Conclusion:

The ‘az aks’ command provides a comprehensive set of functionality to manage Azure Kubernetes Service clusters. It allows users to create, delete, retrieve information, and perform operations on AKS clusters. The examples provided in this article demonstrate some of the common use cases for managing AKS clusters using the Azure CLI.

Related Posts

How to use the command hakyll-init (with examples)

How to use the command hakyll-init (with examples)

Hakyll is a static site generator library written in Haskell. The hakyll-init command is used to generate a new Hakyll sample blog, providing a starting point for creating static websites.

Read More
How to use the command "ytfzf" (with examples)

How to use the command "ytfzf" (with examples)

Introduction In this article, we will explore the various use cases of the ytfzf command, a POSIX script that enables users to find and download videos and music.

Read More
How to use the command 'faillock' (with examples)

How to use the command 'faillock' (with examples)

The ‘faillock’ command is used to display and modify authentication failure record files.

Read More