End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS

Introduction

We will be building a sample web application using dotnet core with any IDE but in my case, I will be using VS Code. The application will be tested in a local Kubernetes cluster before deploying this to Azure Kubernetes Service …


This content originally appeared on DEV Community and was authored by Olalekan Oladiran

Introduction

We will be building a sample web application using dotnet core with any IDE but in my case, I will be using VS Code. The application will be tested in a local Kubernetes cluster before deploying this to Azure Kubernetes Service (AKS). You can also use any language of your choice as long as you can wrap it in a container image; we will be using C# for this project.

Requirements

  • VS Code
  • Docker
  • Azure CLI
  • Azure Account
  • .Net SDK

Create Infrastructure

  • Clone a sample of this repository for this project by running the command:

git clone https://github.com/hpranav/kodekloud.git

  • Change to the repository directory

cd kodekloud/AKS/KodeKloudApp

Image description

Test the Application

Before you test your app, make sure that .Net sdk is installed by checking first using the command

dotnet --list-sdks

Image description
If it is not already installed, go to command pallete by clicking view tab and select Command pallete. Alternatively, you can press command+p buttons together.
Image description
Search or select install New .NET SDK
Image description
Wait for installation to complete and check by running

dotnet --version

Image description

  • Now that you have .Net sdk installed, build your application by running dotnet build

Image description
I am getting the warning message because my dotnet version is version 8 while the version used in the repository is 7.0. To rectify this, I will change the version in my target framework from 7.0 to 8.0
Image description

  • Run dotnet run command to run the application Image description
  • Copy the localhost ip address (http://localhost:5142) and paste it in a new browser to confirm the application. Image description
  • While keeping the application running, you can change the value of the message in appsettings.json file. Refresh the browser and you will see the message changed Image description
  • You can stop the application by pressing ctrl+c

Build your Docker image

  • Ensure that docker is running.
  • Build the docker image by running the command docker build -t mywebapp:v1 .

Image description
NOTE:If you get this error, that means the dotnet version in your Dockerfile is different from the version installed on your local machine. Edit the version in your Dockerfile
Image description

  • List docker image by running docker images

Image description

Containerize your application

  • We will leverage on this command: docker run -d -p 8080:80 [name of your image]

This command will run the image as a daemon using -d switch and exposing it at port 8080 and matching it to target port 80 using -p switch
Image description

  • Check the status of the container by running docker container ls

Image description

  • Navigate to your browser and browse localhost:8080 Image description

Run your Application on local Kubernetes Cluster

We will use kubectl utility to deploy our app to local Kubernetes. The easiest way to configure one node cluster Kubernetes from Docker.

  • Open your Docker desktop
  • Select settings sign
  • choose Kubernetes tab
  • Click the toggle to enable Kubernetes
  • Click Apply & restart Image description
  • Click install. Image description Image description
  • After the installation is completed, check the current context by running the command kubectl config current-context

Image description

  • If the current context is not set to docker-desktop, change it by running the command: kubectl config use-context docker-desktop

Image description

  • Confirm the version of the kubectl by running kubectl --version

Image description

  • Create a new deployment by running this imperative command: kubectl create deployment [deployment-name] --image:[your-image-name] --replicas=[number-of-replicas]

Image description

  • Let's confirm that the deployment is created using kubectl get deployment

Image description
You can see that the 2/2 replicas are up and in running state.

  • To connect to your deployment, you will need to expose it to a service using the command: kubectl expose deployment [deployment-name] --type:LoadBalancer --port=8080 --target-port=80

Image description

  • Verify the service by running kubectl get svc

Image description

  • If you go to localhost:8080, you will see that that your app is running. Image description
  • Remember you have two pods running in your cluster, to verify. which of them is serving you, open another new windows in incognito mode and visit localhost:8080 and compare system name. The two pods are viewed by running kubectl get pod

Image description

  • The first page is served by the second pod if you compare the pod name and system name.
  • The second page (opened in incognito mode) is served by the first pod. Image description Image description

Deploy Azure Kubernetes Service (AKS) Cluster

  • Head over to your Azure portal and search for AKS and select Kubernetes service Image description
  • Click create and select Kubernetes cluster Image description
  • Fill in the Project details: create a new resource group, give a name to your cluster, choose a region and uncheck all availability zone. Leave other settings as default. Image description
  • Change the tab to Node pool. Delete the userpool by checking it and press the delete sign (This is used for testing). Image description
  • Edit the the agentpool by clicking on it. For testing purpose, change the node size to DS2_v2, scale method is manual and node count set to 1. Image description
  • Change max pod per node to 30, delete Taints and select Update Image description
  • Click Integration tab. Click create to create new container registry. Image description
  • In the create container registry page, give a name to your container registry, use the previous resource group and region, change the SKU to Basics and click Ok Image description
  • Change the tab to Review+create in order to validate. Click Create after validation. Image description NOTE: The deployment takes several minutes. Image description Image description

Connect to AKS cluster via Azure CLI

  • Visit AZ-CLI to install AZ CLI
  • Run az --version to check the version. Image description
  • run az login to connect your CLI to your Azure portal if you have not done so.
  • You can also run az account show to view the account you are connected to
  • After logging into your account, set the default to your AKS resource group by running az configure --defaults group=[resource-group-name]

Image description

  • Run az aks get-Credentials --name [AKS name] to download the credentials and merge it to your current user context. Image description
  • Validate if kubectl can access the cluster by running kubectl config current-context

Image description

  • Run kubectl get node to view the node (agentpool) you selected while creating AKS cluster. Image description
  • You can also confirm this by navigating to your Azure portal, open the created cluster, select Node pools under settings and select the Nodes tab. Image description

Push your image to Docker hub

If you create a deployment right now, the status of your pod will be ErrImagePull because the image is on your local Docker and cannot be accessed AKS. Pushing it to Docker hub will make it accessible to create deployment. To push your image, follow these steps:

  • run docker login

Image description

  • Tag the image by running docker build -t <your-dockerhub-username>/<image-name>:<tag> .

Image description

  • Push the image to Docker Hub by running docker push <your-dockerhub-username>/<image-name>:<tag>

Image description
You can confirm the image in your Docker Hub by logging into your Docker through browser and select Repositories
Image description

  • Now that you have your image in your Docker Hub, you can use it to create deployment. Image description
  • You can get the pod also using kubectl get po

Image description
You can also check the deployment and pod in your Azure portal
Image description

  • To access your deployment from outside, expose it by creating service using the command: kubectl expose deployment [deployment-name] --type:LoadBalancer --port=80 --target-port=80

Image description

  • Run kubectl get svc to get the External IP address to access your deployment Image description
  • Paste the External IP to a new browser to check. Image description

Scale your application

  • To scale your deployment, run kubectl scale deployment [deployment-name] --replicas=5

Image description

  • Check the number of pods Image description You can see that there are 5 pods in the cluster according to the number of scale

Pushing Image to Azure Container Registry

You have created an ACR while creating AKS and you are going to push your Docker image to it.

  • Head over to Azure portal and search & select container registries Image description
  • Select your container registry. Image description There are two things that are needed for your AKS node to pull an Image from ACR:
  • Network connectivity - Because SKU selected was Basics during creation of your ACR, the default network access is Public and cannot be changed. Image description
  • IAM policy - AcrPull permission has been assigned by default since you created your ACR together with AKS Image description
  • To push your local image to ACR, tag the image by running the command docker tag local-image-name:tag ACR-login-server/image-name:tag

NOTE: You can get your ACR-login-server from ACR overview page
Image description
Image description

  • To login to ACR from my VS Code, run the command: az acr login --name ACR-login-server

Image description

  • Once the login is succeeded, run docker push ACR-login-server/image-name:tag

Image description
Confirm that the image is inside your ACR by selecting Repositories
Image description

  • Next thing is to use this image to create deployment. Image description
  • Expose the deployment and get the External IP Image description
  • Paste the External IP in a new browser to check Image description You have successfully pushed your Image to ACR and tested that it is working.

Thanks for staying till the end


This content originally appeared on DEV Community and was authored by Olalekan Oladiran


Print Share Comment Cite Upload Translate Updates
APA

Olalekan Oladiran | Sciencx (2025-05-16T00:05:54+00:00) End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS. Retrieved from https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/

MLA
" » End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS." Olalekan Oladiran | Sciencx - Friday May 16, 2025, https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/
HARVARD
Olalekan Oladiran | Sciencx Friday May 16, 2025 » End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS., viewed ,<https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/>
VANCOUVER
Olalekan Oladiran | Sciencx - » End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/
CHICAGO
" » End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS." Olalekan Oladiran | Sciencx - Accessed . https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/
IEEE
" » End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS." Olalekan Oladiran | Sciencx [Online]. Available: https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/. [Accessed: ]
rf:citation
» End-to-End DevOps: Running a .NET App in Kubernetes with Docker, ACR, and AKS | Olalekan Oladiran | Sciencx | https://www.scien.cx/2025/05/16/end-to-end-devops-running-a-net-app-in-kubernetes-with-docker-acr-and-aks/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.