Introduction to Azure AKS

Azure Kubernetes Service (AKS) is a fully-managed Kubernetes service that makes it easy to deploy and manage containerized applications in Azure. With AKS, you can quickly create a production-ready Kubernetes cluster and easily scale it up or down as needed.

AKS provides many benefits, including:

  • Easy setup: You can quickly create a Kubernetes cluster without having to manage the underlying infrastructure.
  • Scalability: AKS allows you to easily scale your cluster up or down based on your application needs.
  • High availability: AKS provides built-in high availability for your applications.
  • Integration with Azure services: AKS integrates with many other Azure services, such as Azure Container Registry and Azure DevOps.
  • Security: AKS provides many security features, such as network security and RBAC (Role-Based Access Control).

Setting up Azure AKS

There are two main ways to set up an AKS cluster in Azure: using the Azure Portal or using the Azure CLI. In this tutorial, we’ll cover both methods.

Setting up AKS using the Azure Portal

To set up an AKS cluster using the Azure Portal, follow these steps:

  1. Sign in to the Azure Portal at https://portal.azure.com/.
  2. Click on “Create a resource” in the left-hand menu.
  3. Search for “Kubernetes Service” and select “Kubernetes Service” from the list of results.
  4. Click on the “Create” button.
  5. Fill in the basic information for your AKS cluster, such as the subscription, resource group, and cluster name.
  6. Choose the Kubernetes version you want to use for your cluster.
  7. Choose the number of nodes you want in your cluster.
  8. Choose the node size and disk size for your nodes.
  9. Choose the authentication method you want to use for your cluster.
  10. Choose the network configuration for your cluster.
  11. Review your settings and click on the “Create” button.

Once your AKS cluster is created, you can connect to it using the Kubernetes CLI (kubectl) or the Azure CLI.

Setting up AKS using the Azure CLI

To set up an AKS cluster using the Azure CLI, follow these steps:

  1. Install the Azure CLI if you haven’t already. You can download it from the official Azure CLI website at https://docs.microsoft.com/en-us/cli/azure/install-azure-cli.
  2. Sign in to the Azure CLI using the following command: az login
  3. Create a resource group for your AKS cluster using the following command:
az group create --name <resource-group-name> --location <location>

Replace <resource-group-name> with the name you want to give your resource group, and <location> with the Azure region you want to use (e.g. “eastus”).

4. Create an AKS cluster using the following command:

az aks create --resource-group <resource-group-name> --name <cluster-name> --node-count <node-count> --node-vm-size <node-vm-size> --generate-ssh-keys

Replace <resource-group-name> with the name of the resource group you created in step 3, <cluster-name> with the name you want to give your AKS cluster, <node-count> with the number of nodes you want in your cluster, and <node-vm-size> with the VM size you want to use for your nodes (e.g. “Standard_DS2_v2”).

5. After running the previous command, it may take a few minutes for your AKS cluster to be created. Once it’s ready, you can connect to it using the following command:

az aks get-credentials --resource-group <resource-group-name> --name <cluster-name>

This command retrieves the credentials for your AKS cluster and adds them to your Kubernetes configuration file.

6. To verify that you can connect to your AKS cluster, run the following command:

kubectl get nodes

This command should display a list of the nodes in your AKS cluster.

Deploying a Sample Application to AKS

Now that you have an AKS cluster set up, let’s deploy a sample application to it. In this tutorial, we’ll deploy a simple “hello world” application using a Kubernetes deployment and service.

  1. Create a new file named hello-world.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: hello-world
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  selector:
    app: hello-world
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

This YAML file defines a Kubernetes deployment and service for our “hello world” application.

2. Apply the YAML file to your AKS cluster using the following command:

kubectl apply -f hello-world.yaml

This command creates the deployment and service for our “hello world” application.

3. To verify that the application is running, run the following command:

kubectl get service hello-world

This command should display the external IP address of the service.

4. Open a web browser and navigate to the external IP address of the service. You should see a “hello world” message.

Congratulations, you have successfully deployed a sample application to your AKS cluster!

Conclusion

In this tutorial, we covered everything you need to know about Azure AKS, including how to set it up using both the Azure Portal and the Azure CLI, and how to deploy a sample application to your AKS cluster. AKS provides many benefits, such as easy setup, scalability, high availability, integration with Azure services, and security. With AKS, you can easily deploy and manage containerized applications in Azure.