Skip to content

Commit 2b5e196

Browse files
CopilotLuizMacedo
andcommitted
Add Kubernetes and Terraform support for eShopOnWeb deployment
Co-authored-by: LuizMacedo <[email protected]>
1 parent 2fcb4e1 commit 2b5e196

20 files changed

+1601
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ According to the prompt, enter an `env name`, and select `subscription` and `loc
8989

9090
You can also run the sample directly locally (See below).
9191

92+
## Deployment Options
93+
94+
This repository supports multiple deployment options:
95+
96+
### 1. Azure Developer CLI (azd) - Recommended
97+
Uses the built-in `azure.yaml` template for quick Azure deployment. See above section.
98+
99+
### 2. Azure Bicep Templates
100+
Traditional Azure deployment using Bicep templates in the `infra/` directory.
101+
102+
### 3. Kubernetes Deployment
103+
Deploy to any Kubernetes cluster using the manifests in the `k8s/` directory.
104+
See [k8s/README.md](k8s/README.md) for detailed instructions.
105+
106+
### 4. Terraform Infrastructure
107+
Deploy Azure infrastructure using Terraform configuration in the `terraform/` directory.
108+
See [terraform/README.md](terraform/README.md) for detailed instructions.
109+
110+
### 5. Docker Compose
111+
Run locally using Docker Compose. See "Running the sample using Docker" section below.
112+
92113
## Running the sample locally
93114
Most of the site's functionality works with just the web application running. However, the site's Admin page relies on Blazor WebAssembly running in the browser, and it must communicate with the server using the site's PublicApi web application. You'll need to also run this project. You can configure Visual Studio to start multiple projects, or just go to the PublicApi folder in a terminal window and run `dotnet run` from there. After that from the Web folder you should run `dotnet run --launch-profile Web`. Now you should be able to browse to `https://localhost:5001/`. The admin part in Blazor is accessible to `https://localhost:5001/admin`
94115

k8s/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# eShopOnWeb Kubernetes Deployment
2+
3+
This directory contains Kubernetes manifests for deploying the eShopOnWeb application to a Kubernetes cluster.
4+
5+
## Prerequisites
6+
7+
- Kubernetes cluster (v1.20+)
8+
- kubectl configured to connect to your cluster
9+
- NGINX Ingress Controller (for external access)
10+
- Docker images built for the application
11+
12+
## Build Docker Images
13+
14+
Before deploying, build the required Docker images:
15+
16+
```bash
17+
# From the repository root
18+
docker build -t eshopwebmvc:latest -f src/Web/Dockerfile .
19+
docker build -t eshoppublicapi:latest -f src/PublicApi/Dockerfile .
20+
```
21+
22+
If using a container registry, tag and push the images:
23+
24+
```bash
25+
# Example for Azure Container Registry
26+
docker tag eshopwebmvc:latest your-registry.azurecr.io/eshopwebmvc:latest
27+
docker tag eshoppublicapi:latest your-registry.azurecr.io/eshoppublicapi:latest
28+
docker push your-registry.azurecr.io/eshopwebmvc:latest
29+
docker push your-registry.azurecr.io/eshoppublicapi:latest
30+
```
31+
32+
Then update the image names in the deployment files.
33+
34+
## Deployment
35+
36+
Deploy the application to Kubernetes:
37+
38+
```bash
39+
# Apply all manifests
40+
kubectl apply -f k8s/
41+
42+
# Or apply them in order:
43+
kubectl apply -f k8s/namespace.yaml
44+
kubectl apply -f k8s/configmap.yaml
45+
kubectl apply -f k8s/secrets.yaml
46+
kubectl apply -f k8s/sqlserver.yaml
47+
kubectl apply -f k8s/web-deployment.yaml
48+
kubectl apply -f k8s/publicapi-deployment.yaml
49+
kubectl apply -f k8s/ingress.yaml
50+
```
51+
52+
## Access the Application
53+
54+
### Using Ingress (recommended)
55+
56+
1. Ensure NGINX Ingress Controller is installed in your cluster
57+
2. Add the following to your `/etc/hosts` file (or equivalent):
58+
```
59+
<ingress-controller-ip> eshoponweb.local
60+
```
61+
3. Access the application at: http://eshoponweb.local
62+
63+
### Using Port Forwarding (for testing)
64+
65+
```bash
66+
# Web application
67+
kubectl port-forward -n eshoponweb service/web-service 8080:80
68+
69+
# Public API
70+
kubectl port-forward -n eshoponweb service/publicapi-service 8081:80
71+
```
72+
73+
Then access:
74+
- Web: http://localhost:8080
75+
- API: http://localhost:8081
76+
77+
## Configuration
78+
79+
### Environment Variables
80+
81+
The application configuration is managed through:
82+
- `configmap.yaml`: Non-sensitive configuration
83+
- `secrets.yaml`: Sensitive data like connection strings
84+
85+
### Database
86+
87+
The deployment includes:
88+
- SQL Server running in a container
89+
- Persistent storage using emptyDir (consider using PersistentVolumes for production)
90+
91+
For production, consider:
92+
- Using an external managed database service
93+
- Implementing proper backup strategies
94+
- Using PersistentVolumes for data persistence
95+
96+
## Scaling
97+
98+
Scale the application components:
99+
100+
```bash
101+
# Scale web frontend
102+
kubectl scale deployment web-deployment -n eshoponweb --replicas=3
103+
104+
# Scale API
105+
kubectl scale deployment publicapi-deployment -n eshoponweb --replicas=3
106+
```
107+
108+
## Monitoring
109+
110+
Check deployment status:
111+
112+
```bash
113+
# Check all resources
114+
kubectl get all -n eshoponweb
115+
116+
# Check pod logs
117+
kubectl logs -f deployment/web-deployment -n eshoponweb
118+
kubectl logs -f deployment/publicapi-deployment -n eshoponweb
119+
kubectl logs -f deployment/sqlserver-deployment -n eshoponweb
120+
```
121+
122+
## Cleanup
123+
124+
Remove the deployment:
125+
126+
```bash
127+
kubectl delete namespace eshoponweb
128+
```
129+
130+
## Notes
131+
132+
- The current configuration uses in-cluster SQL Server with basic authentication
133+
- For production deployments, consider:
134+
- Using managed database services
135+
- Implementing proper secrets management (e.g., Azure Key Vault, HashiCorp Vault)
136+
- Setting up monitoring and logging
137+
- Configuring resource limits and requests appropriately
138+
- Using init containers for database migrations
139+
- Implementing network policies for security

k8s/configmap.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: eshoponweb-config
5+
namespace: eshoponweb
6+
data:
7+
ASPNETCORE_ENVIRONMENT: "Production"
8+
UseOnlyInMemoryDatabase: "false"
9+
ASPNETCORE_URLS: "http://+:80"
10+
# Connection strings will be provided via secrets

0 commit comments

Comments
 (0)