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
Test the Application
Before you test your app, make sure that .Net sdk is installed by checking first using the command
dotnet --list-sdks
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.
Search or select install New .NET SDK
Wait for installation to complete and check by running
dotnet --version
- Now that you have .Net sdk installed, build your application by running
dotnet build
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
- Run
dotnet run
command to run the application - Copy the localhost ip address (http://localhost:5142) and paste it in a new browser to confirm the application.
- 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
- 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 .
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
- List docker image by running
docker images
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
- Check the status of the container by running
docker container ls
- Navigate to your browser and browse localhost:8080
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
- Click install.
- After the installation is completed, check the current context by running the command
kubectl config current-context
- If the current context is not set to docker-desktop, change it by running the command:
kubectl config use-context docker-desktop
- Confirm the version of the kubectl by running
kubectl --version
- Create a new deployment by running this imperative command:
kubectl create deployment [deployment-name] --image:[your-image-name] --replicas=[number-of-replicas]
- Let's confirm that the deployment is created using
kubectl get deployment
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
- Verify the service by running
kubectl get svc
- If you go to localhost:8080, you will see that that your app is running.
- 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
- 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.
Deploy Azure Kubernetes Service (AKS) Cluster
- Head over to your Azure portal and search for AKS and select Kubernetes service
- Click create and select Kubernetes cluster
- 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.
- Change the tab to Node pool. Delete the userpool by checking it and press the delete sign (This is used for testing).
- 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.
- Change max pod per node to 30, delete Taints and select Update
- Click Integration tab. Click create to create new container registry.
- 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
- Change the tab to Review+create in order to validate. Click Create after validation.
NOTE: The deployment takes several minutes.
Connect to AKS cluster via Azure CLI
- Visit AZ-CLI to install AZ CLI
- Run
az --version
to check the version. - 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]
- Run
az aks get-Credentials --name [AKS name]
to download the credentials and merge it to your current user context. - Validate if kubectl can access the cluster by running
kubectl config current-context
- Run
kubectl get node
to view the node (agentpool) you selected while creating AKS cluster. - 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.
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
- Tag the image by running
docker build -t <your-dockerhub-username>/<image-name>:<tag> .
- Push the image to Docker Hub by running
docker push <your-dockerhub-username>/<image-name>:<tag>
You can confirm the image in your Docker Hub by logging into your Docker through browser and select Repositories
- Now that you have your image in your Docker Hub, you can use it to create deployment.
- You can get the pod also using
kubectl get po
You can also check the deployment and pod in your Azure portal
- 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
- Run
kubectl get svc
to get the External IP address to access your deployment - Paste the External IP to a new browser to check.
Scale your application
- To scale your deployment, run
kubectl scale deployment [deployment-name] --replicas=5
- Check the number of pods
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
- Select your container registry.
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.
- IAM policy - AcrPull permission has been assigned by default since you created your ACR together with AKS
- 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
- To login to ACR from my VS Code, run the command:
az acr login --name ACR-login-server
- Once the login is succeeded, run
docker push ACR-login-server/image-name:tag
Confirm that the image is inside your ACR by selecting Repositories
- Next thing is to use this image to create deployment.
- Expose the deployment and get the External IP
- Paste the External IP in a new browser to check
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

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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.