How to Deploy Azure Kubernetes Service with Azure CLI

Azure Kubernetes Service with Azure CLI

How to Deploy Azure Kubernetes Service with Azure CLI

How to Deploy Azure Kubernetes Service with Azure CLI

Deploying an Azure Kubernetes Service (AKS) cluster is straightforward with the Azure CLI. Here’s a step-by-step guide to help you get started:


  1. Azure Subscription: Ensure you have an active Azure subscription. You can sign up for a free account here.
  2. Azure CLI: Install the Azure CLI. You can download and install it from here.

Step 1: Install Azure CLI

If you haven’t installed the Azure CLI yet, you can do so using the following commands:

On Windows:
Download and install from Azure CLI installation page.

On macOS:

brew update && brew install azure-cli

On Linux:

curl -sL | sudo bash

Step 2: Log in to Azure

Open a terminal and log in to your Azure account:

az login

This command will open a browser window where you can log in with your Azure credentials.

Step 3: Create a Resource Group

A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed.

az group create --name MyResourceGroup --location eastus

Step 4: Create an AKS Cluster

Create the AKS cluster using the following command:

az aks create --resource-group MyResourceGroup --name MyAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
  • --resource-group: The name of the resource group.
  • --name: The name of the AKS cluster.
  • --node-count: The number of nodes in the cluster.
  • --enable-addons: Enable monitoring (Azure Monitor) for the cluster.
  • --generate-ssh-keys: Generate SSH keys if you don’t have them already.

Step 5: Connect to the AKS Cluster

To manage and interact with your AKS cluster, you need to configure kubectl, the Kubernetes command-line tool.

  1. Install kubectl:
    az aks install-cli
  2. Get the cluster credentials:
    az aks get-credentials --resource-group MyResourceGroup --name MyAKSCluster
  3. Verify connection:
    kubectl get nodes

Step 6: Deploy an Application to AKS

Now that your AKS cluster is set up and connected, you can deploy your first application.

  1. Create a sample deployment:
    kubectl create deployment myapp --image=nginx
  2. Expose the deployment as a service:
    kubectl expose deployment myapp --type=LoadBalancer --port=80
  3. Get the external IP of the service:
    kubectl get service myapp

    After a few minutes, the EXTERNAL-IP field will show the public IP address of your application.

Additional Tips:

  • Scaling: You can scale your deployment by adjusting the node count or using autoscaling features.
  • Monitoring: Utilize Azure Monitor and Azure Log Analytics for monitoring and logging your AKS cluster.
  • Security: Implement Azure Active Directory integration for secure access and role-based access control (RBAC).

For enquires related with Installation, Configuration and Azure Devops related services, please visit Azure Kubernetes Services and Solution.

Share this post