Configuring Azure Kubernetes Service (AKS) Cluster and running/scaling a .Net Core application

Development Environment Setup

  • Install Docker
  • Enable Kubernetes Cluster on Docker, under Docker -> Settings
  • Install Azure CLI and Azure PowerShell modules

Containerize the application

  • Clone this repo to a folder
  • Open a command prompt and navigate to your project folder.
  • Use the following commands to build and run your Docker image:
  • View the .Net Core application running from a container by navigating to localhost:8000

alt text

Deploy the application to local Kubernetes Cluster

  • Deploy docker image to Kubernetes

    • kubectl command
      • to verify the deployment: kubectl get deployments
      • to verify the replicasets: kubectl get rs
      • to verify the Pods: kubectl get pods
  • Expose the application to outside world, use the following command
  • Verify the service

alt text

Push the image to Azure Container Registry using the Azure CLI

  • Login to Azure
  • Create Azure Resource Group
  • Create Azure Container Registry
    • Verify the Azure Container Registry
  • Push the image to Azure Container Registry
    • Login to Azure Container Registry
      • Tag the docker image prior to push the image to Azure Container Registry
      • Push the tagged image to Azure Container Registry
      • Verify the repository in Azure Container Registry

    alt text

    Create AKS cluster using the Azure CLI

    AKS uses the Service Principal to access other Azure Services like the Azure Container Registry (ACR). It is recommended to register an application in Azure AD and create an identity for the application (i.e. Service Principal)

    • Create Service Principal

    • Create acrID variable
    • Create a role assignment with appid and acrID
    • Create AKS Cluster
    • Get the AKS cluster credentials to update local environment
    • Verify the AKS Cluster in Azure Cloud

    alt text

    Deploy the application to AKS Cluster using .yml file

    • Below is the content of kubeservice-deploy.yml file:
      • Deploy the application to AKS Cluster
      • To monitor the service deployment

      Scale the application and Kubernetes infrastructure

      Scaling Azure Kubernetes Service (AKS) Cluster nodes

      • Get the current nodes
      • Scaling nodes
      • Get the current nodes after scaling

      alt text

      alt text

      Scaling Azure Kubernetes Service (AKS) Cluster pods

      • Verify the current replicas # of application
      • Verify the current deployment
      • Scale the pods to 5
      • Verify the current deployment after scale
      • Verify the current replicas # of application

      alt text

      Update the application then push the image to ACR and update deployment

      • Change the application

      • Create a new image docker build . -t vvkubeserviceacr.azurecr.io/kubeservice:v2

      • Push the image to Azure Container Registry

      • Update the deployment
      • To monitor the deployment
      • Test the updated application

      alt text

      Share the Post: