Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ According to the prompt, enter an `env name`, and select `subscription` and `loc

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

## Deployment Options

This repository supports multiple deployment options:

### 1. Azure Developer CLI (azd) - Recommended
Uses the built-in `azure.yaml` template for quick Azure deployment. See above section.

### 2. Azure Bicep Templates
Traditional Azure deployment using Bicep templates in the `infra/` directory.

### 3. Kubernetes Deployment
Deploy to any Kubernetes cluster using the manifests in the `k8s/` directory.
See [k8s/README.md](k8s/README.md) for detailed instructions.

### 4. Terraform Infrastructure
Deploy Azure infrastructure using Terraform configuration in the `terraform/` directory.
See [terraform/README.md](terraform/README.md) for detailed instructions.

### 5. Docker Compose
Run locally using Docker Compose. See "Running the sample using Docker" section below.

## Running the sample locally
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`

Expand Down
139 changes: 139 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# eShopOnWeb Kubernetes Deployment

This directory contains Kubernetes manifests for deploying the eShopOnWeb application to a Kubernetes cluster.

## Prerequisites

- Kubernetes cluster (v1.20+)
- kubectl configured to connect to your cluster
- NGINX Ingress Controller (for external access)
- Docker images built for the application

## Build Docker Images

Before deploying, build the required Docker images:

```bash
# From the repository root
docker build -t eshopwebmvc:latest -f src/Web/Dockerfile .
docker build -t eshoppublicapi:latest -f src/PublicApi/Dockerfile .
```

If using a container registry, tag and push the images:

```bash
# Example for Azure Container Registry
docker tag eshopwebmvc:latest your-registry.azurecr.io/eshopwebmvc:latest
docker tag eshoppublicapi:latest your-registry.azurecr.io/eshoppublicapi:latest
docker push your-registry.azurecr.io/eshopwebmvc:latest
docker push your-registry.azurecr.io/eshoppublicapi:latest
```

Then update the image names in the deployment files.

## Deployment

Deploy the application to Kubernetes:

```bash
# Apply all manifests
kubectl apply -f k8s/

# Or apply them in order:
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secrets.yaml
kubectl apply -f k8s/sqlserver.yaml
kubectl apply -f k8s/web-deployment.yaml
kubectl apply -f k8s/publicapi-deployment.yaml
kubectl apply -f k8s/ingress.yaml
```

## Access the Application

### Using Ingress (recommended)

1. Ensure NGINX Ingress Controller is installed in your cluster
2. Add the following to your `/etc/hosts` file (or equivalent):
```
<ingress-controller-ip> eshoponweb.local
```
3. Access the application at: http://eshoponweb.local

### Using Port Forwarding (for testing)

```bash
# Web application
kubectl port-forward -n eshoponweb service/web-service 8080:80

# Public API
kubectl port-forward -n eshoponweb service/publicapi-service 8081:80
```

Then access:
- Web: http://localhost:8080
- API: http://localhost:8081

## Configuration

### Environment Variables

The application configuration is managed through:
- `configmap.yaml`: Non-sensitive configuration
- `secrets.yaml`: Sensitive data like connection strings

### Database

The deployment includes:
- SQL Server running in a container
- Persistent storage using emptyDir (consider using PersistentVolumes for production)

For production, consider:
- Using an external managed database service
- Implementing proper backup strategies
- Using PersistentVolumes for data persistence

## Scaling

Scale the application components:

```bash
# Scale web frontend
kubectl scale deployment web-deployment -n eshoponweb --replicas=3

# Scale API
kubectl scale deployment publicapi-deployment -n eshoponweb --replicas=3
```

## Monitoring

Check deployment status:

```bash
# Check all resources
kubectl get all -n eshoponweb

# Check pod logs
kubectl logs -f deployment/web-deployment -n eshoponweb
kubectl logs -f deployment/publicapi-deployment -n eshoponweb
kubectl logs -f deployment/sqlserver-deployment -n eshoponweb
```

## Cleanup

Remove the deployment:

```bash
kubectl delete namespace eshoponweb
```

## Notes

- The current configuration uses in-cluster SQL Server with basic authentication
- For production deployments, consider:
- Using managed database services
- Implementing proper secrets management (e.g., Azure Key Vault, HashiCorp Vault)
- Setting up monitoring and logging
- Configuring resource limits and requests appropriately
- Using init containers for database migrations
- Implementing network policies for security
10 changes: 10 additions & 0 deletions k8s/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: eshoponweb-config
namespace: eshoponweb
data:
ASPNETCORE_ENVIRONMENT: "Production"
UseOnlyInMemoryDatabase: "false"
ASPNETCORE_URLS: "http://+:80"
# Connection strings will be provided via secrets
Loading