Getting Started with Azure Kubernetes Service (AKS)

Welcome to the quick start guide for Azure Kubernetes Service (AKS). This tutorial will walk you through the essential steps to get your first Kubernetes cluster up and running on Azure.

Prerequisites: Before you begin, ensure you have an Azure subscription and the Azure CLI installed and configured.

If you don't have an Azure subscription, you can sign up for a free account.

1. Create an AKS Cluster

The fastest way to create an AKS cluster is by using the Azure CLI. Run the following command, replacing myResourceGroup and myAKSCluster with your desired names:

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

This command creates a resource group and then deploys a basic AKS cluster with one node. The monitoring add-on provides valuable insights into your cluster's performance.

Cluster Deployment Time: Cluster creation can take several minutes. You will see output detailing the progress.

2. Connect to Your Cluster

Once the cluster is deployed, you need to configure the Kubernetes command-line tool, kubectl, to connect to your cluster. If kubectl is not installed, you can install it by following the official Kubernetes documentation.

Use the Azure CLI to get the connection credentials:

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

This command downloads the cluster credentials and merges them into your local kubectl configuration file.

Verify that kubectl can connect to your cluster by listing the nodes:

kubectl get nodes

You should see output listing your cluster's node(s).

3. Deploy a Sample Application

Now that your cluster is ready, let's deploy a simple sample application. We'll use the ubiquitous "Hello World" Nginx web server.

Create a Kubernetes deployment manifest file named nginx-deployment.yaml:

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

Apply the deployment manifest to your cluster:

kubectl apply -f nginx-deployment.yaml

4. Expose Your Application

To make your Nginx application accessible from the internet, you need to create a Kubernetes service. We'll use a LoadBalancer service type.

Create a Kubernetes service manifest file named nginx-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 manifest to your cluster:

kubectl apply -f nginx-service.yaml

It will take a few minutes for the Azure load balancer to be provisioned and assigned an external IP address. You can check the status using:

kubectl get service nginx-service

Look for the EXTERNAL-IP field. Once it shows an IP address, you can access your Nginx application by browsing to that IP address in your web browser.

Next Steps

Congratulations! You've successfully deployed and exposed an application on AKS. From here, you can explore more advanced topics such as:

Continue to Deploy an Application