Azure Kubernetes Service (AKS)

Deploy Your First Application to Azure Kubernetes Service

This guide will walk you through the essential steps to get your application running on Azure Kubernetes Service (AKS) with minimal configuration.

Step 1: Prerequisites

Before you begin, ensure you have the following:

Log in to your Azure account:

az login

Set your active subscription:

az account set --subscription ""

Step 2: Create an AKS Cluster

Use the Azure CLI to create a new AKS cluster. This command will create a resource group and an AKS cluster named myAKSCluster.

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

This process may take several minutes to complete.

Step 3: Connect kubectl to Your Cluster

Once the cluster is created, configure kubectl to connect to it:

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

Verify the connection:

kubectl get nodes

You should see your cluster's nodes listed.

Step 3: Deploy a Sample Application

We'll deploy a simple Nginx application. Create a YAML file named azure-aks-quickstart.yaml with the following content:

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

Apply this deployment to your cluster:

kubectl apply -f azure-aks-quickstart.yaml

Step 4: Expose Your Application

To make your application accessible from the internet, create a Kubernetes Service of type LoadBalancer. Create a file named azure-aks-quickstart-service.yaml:

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

Apply the service configuration:

kubectl apply -f azure-aks-quickstart-service.yaml

Get the external IP address of your service:

kubectl get service nginx-service

It might take a minute or two for the external IP address to be assigned. Once it is, you can access your Nginx application by navigating to that IP address in your web browser.

Important: Remember to clean up your resources to avoid ongoing charges. You can delete the resource group:
az group delete --name myResourceGroup --yes --no-wait

Congratulations! You have successfully deployed and exposed your first application on Azure Kubernetes Service.

Explore Advanced Concepts