Skip to content

Commit 33d3ab9

Browse files
CopilotLuizMacedo
andcommitted
Add Kubernetes and Terraform deployment configurations
Co-authored-by: LuizMacedo <[email protected]>
1 parent b036375 commit 33d3ab9

29 files changed

+1841
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,19 @@ pub/
260260
.devcontainer
261261

262262
.azure
263+
264+
# Terraform
265+
**/.terraform/*
266+
*.tfstate
267+
*.tfstate.*
268+
.terraform.lock.hcl
269+
crash.log
270+
crash.*.log
271+
*.tfvars
272+
!terraform.tfvars.example
273+
override.tf
274+
override.tf.json
275+
*_override.tf
276+
*_override.tf.json
277+
.terraformrc
278+
terraform.rc

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,65 @@ You should be able to make requests to localhost:5106 for the Web project, and l
161161
162162
You can also run the applications by using the instructions located in their `Dockerfile` file in the root of each project. Again, run these commands from the root of the solution (where the .sln file is located).
163163
164+
## Deployment Options
165+
166+
### Kubernetes Deployment
167+
168+
Deploy eShopOnWeb to a Kubernetes cluster using the provided manifests and Kustomize configurations.
169+
170+
**Quick Start:**
171+
```bash
172+
# Build and push images
173+
docker-compose build
174+
docker tag eshopwebmvc:latest <your-registry>/eshopwebmvc:latest
175+
docker tag eshoppublicapi:latest <your-registry>/eshoppublicapi:latest
176+
docker push <your-registry>/eshopwebmvc:latest
177+
docker push <your-registry>/eshoppublicapi:latest
178+
179+
# Deploy to Kubernetes
180+
cd deploy/k8s
181+
kubectl apply -k .
182+
```
183+
184+
For detailed instructions, environment-specific deployments, and configuration options, see [deploy/k8s/README.md](deploy/k8s/README.md).
185+
186+
**Supported Platforms:**
187+
- Azure Kubernetes Service (AKS)
188+
- Amazon Elastic Kubernetes Service (EKS)
189+
- Google Kubernetes Engine (GKE)
190+
- On-premises Kubernetes clusters
191+
192+
### Terraform Infrastructure as Code
193+
194+
Provision and manage Azure infrastructure using Terraform, including AKS cluster, networking, and container registry.
195+
196+
**Quick Start:**
197+
```bash
198+
cd deploy/terraform
199+
terraform init
200+
terraform plan
201+
terraform apply
202+
```
203+
204+
For comprehensive documentation on modules, variables, environments, and best practices, see [deploy/terraform/README.md](deploy/terraform/README.md).
205+
206+
**Provisioned Resources:**
207+
- Azure Kubernetes Service (AKS)
208+
- Azure Container Registry (ACR)
209+
- Virtual Network and Subnets
210+
- Network Security Groups
211+
- Storage Account
212+
213+
### Azure Bicep Deployment
214+
215+
The repository also includes Azure Bicep templates in the `infra/` directory for provisioning Azure resources such as:
216+
- Azure App Service
217+
- Azure Container Instances (ACI)
218+
- Azure SQL Database
219+
- Key Vault
220+
221+
See the `infra/` directory for Bicep deployment templates.
222+
164223
## Community Extensions
165224

166225
We have some great contributions from the community, and while these aren't maintained by Microsoft we still want to highlight them.

deploy/k8s/README.md

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# Kubernetes Deployment Guide
2+
3+
This directory contains Kubernetes manifests for deploying the eShopOnWeb application to a Kubernetes cluster.
4+
5+
## Prerequisites
6+
7+
- Kubernetes cluster (AKS, EKS, GKE, or local cluster like minikube/kind)
8+
- `kubectl` CLI installed and configured
9+
- Container images built and pushed to a container registry (ACR, Docker Hub, etc.)
10+
- (Optional) `kustomize` CLI for environment-specific deployments
11+
12+
## Architecture
13+
14+
The deployment includes:
15+
- **Web Application** (eshop-web): Frontend MVC application
16+
- **Public API** (eshop-publicapi): Backend REST API
17+
- **ConfigMap**: Application configuration
18+
- **Secret**: Sensitive configuration data
19+
- **Services**: ClusterIP for API, LoadBalancer for Web
20+
- **Ingress**: Optional ingress for external access
21+
22+
## Quick Start
23+
24+
### 1. Build and Push Container Images
25+
26+
First, build the container images and push them to your registry:
27+
28+
```bash
29+
# From the repository root
30+
docker-compose build
31+
32+
# Tag and push to your registry (e.g., Azure Container Registry)
33+
docker tag eshopwebmvc:latest <your-registry>.azurecr.io/eshopwebmvc:latest
34+
docker tag eshoppublicapi:latest <your-registry>.azurecr.io/eshoppublicapi:latest
35+
36+
docker push <your-registry>.azurecr.io/eshopwebmvc:latest
37+
docker push <your-registry>.azurecr.io/eshoppublicapi:latest
38+
```
39+
40+
### 2. Update Kustomization
41+
42+
Edit `kustomization.yaml` to point to your container registry:
43+
44+
```yaml
45+
images:
46+
- name: eshopwebmvc
47+
newName: <your-registry>.azurecr.io/eshopwebmvc
48+
newTag: latest
49+
- name: eshoppublicapi
50+
newName: <your-registry>.azurecr.io/eshoppublicapi
51+
newTag: latest
52+
```
53+
54+
### 3. Deploy Using kubectl
55+
56+
```bash
57+
# Deploy all resources
58+
kubectl apply -k .
59+
60+
# Or deploy individual manifests
61+
kubectl apply -f namespace.yaml
62+
kubectl apply -f configmap.yaml
63+
kubectl apply -f secret.yaml
64+
kubectl apply -f web-deployment.yaml
65+
kubectl apply -f web-service.yaml
66+
kubectl apply -f publicapi-deployment.yaml
67+
kubectl apply -f publicapi-service.yaml
68+
kubectl apply -f ingress.yaml
69+
```
70+
71+
### 4. Verify Deployment
72+
73+
```bash
74+
# Check namespace
75+
kubectl get namespaces | grep eshoponweb
76+
77+
# Check pods
78+
kubectl get pods -n eshoponweb
79+
80+
# Check services
81+
kubectl get services -n eshoponweb
82+
83+
# Get Web service external IP (if LoadBalancer)
84+
kubectl get service eshop-web-service -n eshoponweb
85+
```
86+
87+
## Environment-Specific Deployments
88+
89+
Use Kustomize overlays for different environments:
90+
91+
### Development
92+
```bash
93+
kubectl apply -k overlays/dev/
94+
```
95+
96+
### Staging
97+
```bash
98+
kubectl apply -k overlays/staging/
99+
```
100+
101+
### Production
102+
```bash
103+
kubectl apply -k overlays/production/
104+
```
105+
106+
## Configuration
107+
108+
### ConfigMap
109+
Edit `configmap.yaml` to change application settings:
110+
- `ASPNETCORE_ENVIRONMENT`: Development, Staging, Production
111+
- `UseOnlyInMemoryDatabase`: true/false
112+
- `ASPNETCORE_HTTP_PORTS`: HTTP port
113+
114+
### Secrets
115+
Update `secret.yaml` with your database credentials:
116+
- `CATALOG_DB_CONNECTION`: Catalog database connection string
117+
- `IDENTITY_DB_CONNECTION`: Identity database connection string
118+
119+
⚠️ **Important**: In production, use proper secret management (Azure Key Vault, Kubernetes Secrets, Sealed Secrets, etc.)
120+
121+
## Private Container Registry
122+
123+
If using a private container registry, create a registry secret:
124+
125+
```bash
126+
kubectl create secret docker-registry registry-credentials \
127+
--docker-server=<your-registry>.azurecr.io \
128+
--docker-username=<username> \
129+
--docker-password=<password> \
130+
--docker-email=<email> \
131+
-n eshoponweb
132+
```
133+
134+
Then uncomment the `imagePullSecrets` section in deployment files.
135+
136+
## Ingress Configuration
137+
138+
The included `ingress.yaml` uses NGINX Ingress Controller. Update annotations for your ingress controller:
139+
140+
### For Azure Application Gateway Ingress Controller:
141+
```yaml
142+
annotations:
143+
kubernetes.io/ingress.class: azure/application-gateway
144+
appgw.ingress.kubernetes.io/ssl-redirect: "true"
145+
```
146+
147+
### Update the host:
148+
```yaml
149+
spec:
150+
rules:
151+
- host: your-domain.com
152+
```
153+
154+
## Monitoring and Scaling
155+
156+
### View logs
157+
```bash
158+
kubectl logs -f deployment/eshop-web -n eshoponweb
159+
kubectl logs -f deployment/eshop-publicapi -n eshoponweb
160+
```
161+
162+
### Scale deployments
163+
```bash
164+
kubectl scale deployment eshop-web --replicas=3 -n eshoponweb
165+
kubectl scale deployment eshop-publicapi --replicas=3 -n eshoponweb
166+
```
167+
168+
### Horizontal Pod Autoscaling
169+
```bash
170+
kubectl autoscale deployment eshop-web --cpu-percent=70 --min=2 --max=10 -n eshoponweb
171+
```
172+
173+
## Validation
174+
175+
Validate manifests before applying:
176+
177+
```bash
178+
# Dry-run validation
179+
kubectl apply -k . --dry-run=client
180+
181+
# Server-side dry-run
182+
kubectl apply -k . --dry-run=server
183+
184+
# Validate individual files
185+
kubectl apply -f web-deployment.yaml --dry-run=client
186+
```
187+
188+
## Cleanup
189+
190+
To remove all resources:
191+
192+
```bash
193+
# Using kustomize
194+
kubectl delete -k .
195+
196+
# Or delete namespace (removes all resources)
197+
kubectl delete namespace eshoponweb
198+
```
199+
200+
## Troubleshooting
201+
202+
### Pods not starting
203+
```bash
204+
kubectl describe pod <pod-name> -n eshoponweb
205+
kubectl logs <pod-name> -n eshoponweb
206+
```
207+
208+
### Service not accessible
209+
```bash
210+
kubectl get endpoints -n eshoponweb
211+
kubectl describe service eshop-web-service -n eshoponweb
212+
```
213+
214+
### Image pull errors
215+
- Verify registry credentials
216+
- Check image name and tag
217+
- Ensure imagePullSecrets is configured
218+
219+
## Compatibility
220+
221+
These manifests are compatible with:
222+
- Azure Kubernetes Service (AKS)
223+
- Amazon Elastic Kubernetes Service (EKS)
224+
- Google Kubernetes Engine (GKE)
225+
- On-premises Kubernetes clusters
226+
- Local development clusters (minikube, kind, k3s)
227+
228+
## Additional Resources
229+
230+
- [Kubernetes Documentation](https://kubernetes.io/docs/)
231+
- [Kustomize Documentation](https://kustomize.io/)
232+
- [Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/)
233+
- [Kubectl Cheat Sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)

deploy/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: eshop-config
5+
namespace: eshoponweb
6+
data:
7+
ASPNETCORE_ENVIRONMENT: "Production"
8+
UseOnlyInMemoryDatabase: "true"
9+
ASPNETCORE_HTTP_PORTS: "8080"
10+
ASPNETCORE_HTTPS_PORTS: "8443"

deploy/k8s/ingress.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: eshop-ingress
5+
namespace: eshoponweb
6+
annotations:
7+
# Annotations for NGINX Ingress Controller
8+
nginx.ingress.kubernetes.io/rewrite-target: /
9+
nginx.ingress.kubernetes.io/ssl-redirect: "true"
10+
# For Azure Application Gateway Ingress Controller, use:
11+
# kubernetes.io/ingress.class: azure/application-gateway
12+
# appgw.ingress.kubernetes.io/ssl-redirect: "true"
13+
spec:
14+
ingressClassName: nginx
15+
rules:
16+
- host: eshoponweb.local
17+
http:
18+
paths:
19+
- path: /
20+
pathType: Prefix
21+
backend:
22+
service:
23+
name: eshop-web-service
24+
port:
25+
number: 80
26+
- path: /api
27+
pathType: Prefix
28+
backend:
29+
service:
30+
name: eshop-publicapi-service
31+
port:
32+
number: 80
33+
# Uncomment to enable TLS
34+
# tls:
35+
# - hosts:
36+
# - eshoponweb.local
37+
# secretName: eshop-tls-secret

0 commit comments

Comments
 (0)