In the fast-paced world of modern web development, containerization and orchestration technologies like Docker and Kubernetes have become essential tools for building, deploying, and managing applications. For developers working with .NET (especially .NET Core and later) on the backend and Angular on the frontend, understanding these technologies is more than just a nice-to-have—it's critical for efficient development and scalable deployment.
This blog is aimed at .NET and Angular developers who want to get up to speed with Docker and Kubernetes. We’ll cover the basics, dive into setting up a simple application using Docker, and explore how Kubernetes can help manage containers in a production-ready environment.
Why Docker and Kubernetes Matter
Before diving into the "how", let’s answer the "why".
The Old Way
Traditionally, deploying .NET applications (especially .NET Framework) was tightly coupled with Windows servers, IIS configurations, and heavyweight deployments. On the frontend, Angular apps were often served through static file hosting or bundled with backends, adding complexity to deployments.
Each environment—dev, staging, production—could behave differently. Dependencies might vary. Things would “work on my machine” but fail elsewhere.
Enter Docker
Docker allows developers to containerize their applications. A container is a lightweight, standalone, executable package that includes everything needed to run the app: code, runtime, libraries, and dependencies. Containers eliminate the "it works on my machine" problem.
For a .NET and Angular stack:
-
Docker can run your .NET API in a Linux or Windows container.
-
It can build and serve your Angular SPA inside an NGINX container.
-
Both can be run together using Docker Compose.
Enter Kubernetes
Kubernetes (K8s) takes containers a step further. It allows you to:
-
Deploy and manage multiple containers (microservices or monoliths) at scale.
-
Handle auto-scaling, self-healing, load balancing, and rolling updates.
-
Deploy in cloud-native environments or on-premises.
Kubernetes is a container orchestration platform—a powerful tool to manage containers in production.
Setting the Scene: A Sample Application
Let’s imagine a basic web app:
-
Backend: ASP.NET Core Web API that connects to a database.
-
Frontend: Angular app that consumes the API.
-
Database: PostgreSQL.
We want to:
-
Containerize both frontend and backend.
-
Run them locally using Docker Compose.
-
Deploy the same setup to Kubernetes.
Step 1: Dockerizing the .NET Backend
Assume you have a .NET 7 Web API project called MyApp.API
.
Dockerfile for .NET API:
Key Points:
-
Two-stage build: minimizes image size.
-
Uses official Microsoft base images.
-
Publishes app in Release mode.
Step 2: Dockerizing the Angular Frontend
Let’s say your Angular project is named myapp-client
.
Dockerfile for Angular App:
Optional NGINX Config (nginx.conf
):
Step 3: Docker Compose for Local Development
Create a docker-compose.yml
file to run everything together.
Running It:
This setup brings up:
-
.NET API on http://localhost:5000
-
Angular app on http://localhost:4200
-
PostgreSQL database on port 5432
Step 4: Kubernetes — Going Beyond Local
Once your app works locally in Docker, you can move to Kubernetes. There are different ways to deploy:
-
Minikube (local cluster)
-
Docker Desktop Kubernetes
-
AKS (Azure Kubernetes Service)
-
EKS (AWS), GKE (Google)
Let’s focus on a basic Kubernetes deployment using manifests.
Kubernetes Deployment Files
You’ll need:
-
Deployment and Service for each component.
-
A ConfigMap or Secret for credentials (optional).
-
A PersistentVolume for PostgreSQL.
API Deployment (api-deployment.yaml
):
Angular Frontend (client-deployment.yaml
):
PostgreSQL (db-deployment.yaml
):
Step 5: Deploying to Kubernetes
To deploy the app:
Check pods and services:
Step 6: CI/CD Integration (Optional but Powerful)
You can automate Docker image builds and Kubernetes deployments using CI/CD pipelines with:
-
GitHub Actions
-
Azure DevOps
-
GitLab CI
Example GitHub Actions steps:
-
Build Docker image
-
Push to container registry
-
Deploy to Kubernetes cluster
Comments
Post a Comment