Introduction to AKS
Azure Kubernetes Service (AKS) makes it simple to deploy, manage, and scale your containerized applications using Kubernetes on Azure. AKS offers the benefits of Kubernetes without the complexity of managing the control plane or underlying infrastructure.
This tutorial will guide you through the essential steps to get your first Kubernetes cluster up and running on Azure.
Prerequisites
Before you begin, ensure you have the following:
- An Azure 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.
- The `kubectl` command-line tool installed.
Step-by-Step Guide
-
Sign in to Azure
Open your terminal or command prompt and sign in to your Azure account:
az loginThis command will open a browser window for you to authenticate.
-
Create a Resource Group
A resource group is a logical container into which Azure resources are deployed and managed. You'll need to create one before creating your AKS cluster.
Replace
myResourceGroupwith your desired name andeastuswith your preferred Azure region.az group create --name myResourceGroup --location eastus -
Create an AKS Cluster
Now, create your AKS cluster. This command will deploy a basic cluster with a single node pool.
Replace
myAKSClusterwith your desired cluster name.az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keysThis process can take several minutes.
Note: For production environments, consider configuring multiple node pools, autoscaling, and network policies for enhanced availability and security.
-
Connect to the Cluster
Configure `kubectl` to connect to your AKS cluster. The
az aks get-credentialscommand downloads credentials and configures the Azure CLI to use them.az aks get-credentials --resource-group myResourceGroup --name myAKSClusterVerify that the `kubectl` connection to your cluster is successful:
kubectl get nodesYou should see output listing the nodes in your cluster.
-
Deploy an Application
Let's deploy a simple sample application to your cluster. We'll use a basic Nginx deployment.
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: 80Save the above content as
nginx-deployment.yamland apply it using:kubectl apply -f nginx-deployment.yaml -
Expose the Application
To make your application accessible from the internet, you need to expose it using a Kubernetes Service of type
LoadBalancer.apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancerSave the above content as
nginx-service.yamland apply it:kubectl apply -f nginx-service.yamlIt will take a few minutes for a public IP address to be assigned to the load balancer.
-
Access Your Application
Get the external IP address of your service:
kubectl get service nginx-serviceOnce the
EXTERNAL-IPfield shows an IP address, you can access your Nginx application by opening a web browser and navigating to that IP address.Congratulations! You have successfully deployed and exposed a containerized application on Azure Kubernetes Service.
Next Steps
- Explore more advanced deployment strategies and Kubernetes objects.
- Learn about scaling your AKS cluster and applications.
- Integrate with Azure services like Azure Monitor for logging and monitoring.
- Secure your AKS cluster with network policies and Azure Active Directory integration.
For more in-depth information, please refer to the official Azure Kubernetes Service documentation.