Skip to content

ArmDeveloperEcosystem/workshop-multiarch-aks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Architectural Kubernetes Cluster on Azure

This tutorial provides a step-by-step guide to create and deploy a multi-architectural Kubernetes cluster on Azure. Follow the instructions below to set up your environment, build multi-architecture container images, and deploy them to your Azure Kubernetes Service (AKS) cluster.

Prerequisites

Before you begin, ensure you have the following installed:

  • Azure CLI.
  • Docker with Buildx enabled.
  • Terraform.
  • Kubernetes CLI (kubectl)

You will of course also need access to an Azure subscription.

Steps

1. Set Up Azure CLI

  1. Authenticate with Azure:

    az login
  2. Verify your Azure account:

    az account show

    If the active Azure subscription is not correct, follow these steps to change it:

    1. List all available subscriptions:

      az account list --output table
    2. Set the desired subscription as active:

      az account set --subscription "<subscription-id>"
    3. Verify the active subscription:

      az account show

2. Configure Terraform

  1. Navigate to the terraform directory

    cd terraform
  2. Initialize Terraform:

    terraform init
  3. Plan the infrastructure:

    terraform plan -var="subscription_id=$(az account show --query id --output tsv)"

    Review the plan before applying. Ensure that your actively Azure subscription is the correct one.

  4. Apply the Terraform configuration:

    terraform apply -var="subscription_id=$(az account show --query id --output tsv)"

    Make sure you note the deployment name of the ACR, you'll need that for later.

3. Build and Push Multi-Architecture Images

  1. Navigate to the go directory:

    Back out of the terraform directory if you are still into it:

    cd ..

    Then go into the go directory:

    cd go
  2. Log in to Azure Container Registry (ACR):

    az acr login --name <acr-name>
  3. Set up Docker Buildx:

    docker buildx create --name multiarch --use --bootstrap
  4. Build and push the multi-architecture image:

    docker buildx build -t <acr-name>.azurecr.io/multi-arch:latest --platform linux/amd64,linux/arm64 --push .

4. Deploy initial AKS workload

  1. Navigate to the aks directory:

    Back out of the go directory if you are still into it:

    cd ..

    Then go into the aks directory:

    cd aks
  2. Get AKS credentials:

    az aks get-credentials --resource-group <resource-group-name> --name <aks-name> --overwrite-existing
  3. Update the deployment YAML files with the ACR name:

    Open each deployment YAML file (arm64-deployment.yaml, amd64-deployment.yaml, multi-arch-deployment.yaml) and replace <your deployed ACR name> with the name of your ACR you deployed via Terraform.

    For example, in line 21 of multi-arch-deployment.yaml:

    image: <your deployed ACR name>.azurecr.io/multi-arch:latest

    Save the changes to the YAML files.

  4. Deploy the service:

    kubectl apply -f hello-service.yaml
  5. Deploy the ARM64 workload:

    kubectl apply -f arm64-deployment.yaml

5. Verify the Deployment

  1. Check the services:

    kubectl get svc

    You should see the service we deployed, along with an external facing IP address.

  2. Test the service:

    Using that external IP address, send a ping to the service:

    curl -w '\n' http://<IP-of-your-AKS>

    You should get a reply from that service that confirms the go application is running, and which architecture the application is running on.

6. Deploy a second AKS workload

  1. Deploy the AMD64 workload:

    kubectl apply -f amd64-deployment.yaml
  2. Verify the pods:

    kubectl get pods

    You should see both workloads on your cluster now.

  3. Using the same external IP address, send more pings to the service:

    curl -w '\n' http://<IP-of-your-AKS>

    Do this a couple of times, and you should see two different kinds of responses. Showing the go application is running on both amd and arm based nodes.

7. Deploy a third multi-architectural AKS workload

  1. Deploy the multi-architecture workload:

    kubectl apply -f multi-arch-deployment.yaml
  2. Verify the pods:

    kubectl get pods

    You will now see three different pods for our three deployments

  3. Perform multiple requests to test load balancing:

    for i in $(seq 1 20); do curl -w '\n' http://<IP-of-your-AKS>; done

    You will now get a variety of message types back.

    Some will be from the application deployments that we assigned to run on amd or arm. Others will be on the multi architectural deployment that could be running on both amd and arm based compute.

    The load balance will automatically direct traffic to your various pods that in a real world scenario will be completely invisible to your end user.

Notes

  • Ensure your ACR is attached to your AKS cluster: If you deployed using the terraform from this repo, this is already configured for you and you should not need to do this step.

    However, if you pushed your docker image to a different ACR, you can link it to your AKS with the following Azure CLI command:

    az aks update --name <aks-name> --resource-group <resource-group-name> --attach-acr <acr-name>

    Or:

    az aks update --name <aks-name> --resource-group <resource-group-name> --attach-acr <acr-resource-id>

Cleanup

To avoid unnecessary costs, delete the resources when you're done:

  1. Navigate to the terraform directory:

    Back out of the aks directory if you are still into it:

    cd ..

    Go back into your terraform folder:

    cd terraform
  2. Destroy the infrastructure using Terraform:

    terraform destroy -var="subscription_id=$(az account show --query id --output tsv)"

    Confirm the prompt to proceed with the destruction of resources.

Conclusion

You have successfully created and deployed a multi-architectural Kubernetes cluster on Azure. This setup allows you to run workloads across different architectures seamlessly.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published