Getting Started with Azure Kubernetes Service (AKS)
This guide will walk you through the essential steps to create and deploy your first application on Azure Kubernetes Service (AKS). AKS simplifies deploying, managing, and scaling containerized applications using Kubernetes on Azure.
Prerequisites
Before you begin, ensure you have the following:
- An Azure account with an active subscription. If you don't have one, you can create a free account.
- The Azure CLI installed and configured. You can find installation instructions here.
- A basic understanding of containers and Docker.
Step 1: Create an AKS Cluster
The most common way to create an AKS cluster is using the Azure CLI. This command creates a new resource group and an AKS cluster within it.
Define Cluster Parameters
Choose a name for your cluster and the region where you want to deploy it.
Run the Azure CLI Command
Open your terminal or command prompt and execute the following command:
az aks create \
--resource-group myResourceGroup \
--name myAKSCluster \
--node-count 1 \
--enable-addons monitoring \
--generate-ssh-keys
This command will create a cluster with one node. You can adjust --node-count as needed.
Verify Cluster Creation
It might take a few minutes for the cluster to be provisioned. You can check its status:
az aks show \
--resource-group myResourceGroup \
--name myAKSCluster \
--query "provisioningState"
The output should be "Succeeded".
Step 2: Connect to Your Cluster
To interact with your AKS cluster, you need to configure the Kubernetes command-line client, kubectl, to connect to it. The Azure CLI can fetch the credentials for you.
Get Cluster Credentials
Run the following command:
az aks get-credentials \
--resource-group myResourceGroup \
--name myAKSCluster
This command merges the Kubernetes cluster details into your local ~/.kube/config file.
Verify kubectl Configuration
Check that kubectl is connected to your cluster:
kubectl config current-context
And list the nodes in your cluster:
kubectl get nodes
Step 3: Deploy a Sample Application
Now that your cluster is ready, let's deploy a simple "Hello, World!" web application. We'll use a basic YAML manifest file.
Create a Deployment Manifest
Create a file named azure-vote.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-back
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-back
template:
metadata:
labels:
app: azure-vote-back
spec:
containers:
- name: azure-vote-back
image: mcr.microsoft.com/azure-voting-app-backend
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-front
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: azure-vote-back
Apply the Manifest
Deploy the application using kubectl apply:
kubectl apply -f azure-vote.yaml
Get the Application's IP Address
It will take a few minutes for the external IP address to be assigned. You can get it by running:
kubectl get service azure-vote-front
Look for the EXTERNAL-IP field. Once it's assigned, you can access your application by browsing to that IP address.
Note: The first time you run az aks get-credentials, you might be prompted to install the kubectl command. Follow the on-screen instructions.
Next Steps
Congratulations! You've successfully deployed a containerized application to AKS. Here are some suggestions for what to do next:
- Explore more advanced deployment strategies in the Deploy Applications section.
- Learn about managing and scaling your AKS cluster.
- Dive into AKS networking and security features.
Tip: For production environments, consider using Azure Container Registry (ACR) to store your Docker images and configure RBAC for secure access.