Microsoft Docs

Your source for technical documentation.

Getting Started with Azure Kubernetes Service (AKS)

This guide will walk you through the essential steps to set up and begin using Azure Kubernetes Service (AKS), Microsoft's managed Kubernetes offering in Azure. AKS simplifies deploying, managing, and scaling containerized applications.

Prerequisites

Before you begin, ensure you have the following:

Step 1: Create an AKS Cluster

The most straightforward way to create an AKS cluster is using the Azure CLI.

Create a Resource Group

First, create a resource group to hold your AKS cluster and its related resources.

az group create --name myResourceGroup --location eastus

Create the AKS Cluster

Now, create the AKS cluster. This command creates a basic cluster with default settings. You can customize node count, Kubernetes version, and more.

az aks create \
    --resource-group myResourceGroup \
    --name myAKSCluster \
    --node-count 1 \
    --enable-addons monitoring \
    --generate-ssh-keys

This command might take a few minutes to complete.

Note: For production environments, consider using a higher node count, enabling auto-scaling, and configuring advanced networking and security features.

Step 2: Connect to Your Cluster

Once the cluster is created, you need to configure the Kubernetes command-line client, kubectl, to connect to your cluster.

Get Cluster Credentials

Use the Azure CLI to fetch the credentials for your AKS cluster and merge them into your kubectl configuration.

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

This command downloads credentials and configures kubectl to use them.

Verify Cluster Connection

Verify that kubectl is connected to your cluster by listing the nodes.

kubectl get nodes

You should see your AKS node(s) listed with a Ready status.

Step 3: Deploy a Sample Application

Let's deploy a simple Nginx application to your AKS cluster to test the deployment process.

Create a Deployment

Create a Kubernetes Deployment definition file (e.g., nginx-deployment.yaml).

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

Apply the deployment to your cluster:

kubectl apply -f nginx-deployment.yaml

Create a Service

To access the Nginx application from outside the cluster, you need to create a Kubernetes Service. This example uses a LoadBalancer service type.

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

Apply the service definition:

kubectl apply -f nginx-service.yaml

Get the External IP Address

Wait a few minutes for the LoadBalancer to provision and then get the external IP address assigned to the service.

kubectl get service nginx-service

Look for the EXTERNAL-IP field. Once it's populated, you can access your Nginx application by navigating to that IP address in your web browser.

Next Steps

Congratulations! You have successfully created an AKS cluster, connected to it, and deployed a sample application. From here, you can explore more advanced topics: