Skip to main content
Deploying an ASP.NET Core Web App with Docker images to a Kubernetes environment involves creating deployments, exposing services, and scaling replicas. This guide walks you through running your app on a local Kubernetes cluster using kubectl.

Table of Contents

  1. Verify Kubernetes Version
  2. Create a Deployment
  3. Expose the Deployment as a Service
  4. Display the Machine Name in the Web App
  5. Build and Tag a New Docker Image
  6. Redeploy Using Version 2
  7. Test the Load Balancer
  8. Command Reference Table
  9. Links and References

1. Verify Kubernetes Version

Before deploying, confirm the kubectl client and the local cluster version:
Sample output:
Keeping your kubectl client in sync with the server helps avoid compatibility issues.

2. Create a Deployment

Create a Deployment named kodekloudapp using the kodekloudapp:v1 image with 2 replicas:
Verify:
Expected output:

3. Expose the Deployment as a Service

Expose the Deployment on port 8080 (host) → 80 (container). On a local cluster this defaults to a NodePort service, but in cloud environments it provisions a load balancer.
Check the Service:
Sample output:
Open your browser at http://localhost:8080 to see the running app.
On local clusters, LoadBalancer maps to a NodePort. When you move to AKS, this will create a cloud load balancer.

4. Display the Machine Name in the Web App

To confirm traffic distribution across replicas, update the Razor page to display the machine name. Edit Pages/Index.cshtml:
Save changes and restart the app locally to confirm the additional line appears.

5. Build and Tag a New Docker Image

After updating the code, build a new image tagged kodekloudapp:v2:
List your local images:
You should see both v1 and v2 tags:

6. Redeploy Using Version 2

First, clean up existing resources:
Recreate the Deployment with the v2 image:
Expose it again:
Verify:

7. Test the Load Balancer

Visit http://localhost:8080 in two different browser sessions. You’ll see the Machine field alternate between replica hosts, confirming load balancing across pods.

8. Command Reference Table


Watch Video