This guide will walk you through the essential steps to get your application running on Azure Kubernetes Service (AKS) with minimal configuration.
Before you begin, ensure you have the following:
kubectl
, the Kubernetes command-line tool, installed.Log in to your Azure account:
az login
Set your active subscription:
az account set --subscription ""
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.
kubectl
to Your ClusterOnce 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.
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
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.
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