|
| 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 |
0 commit comments