This guide covers deploying the Wanna Fit application to various environments using Docker, Kubernetes, and CI/CD pipelines.
- Docker (v20.10+)
- Kubernetes (v1.21+)
- kubectl (v1.21+)
- Git (v2.30+)
- Python (v3.11+)
- Container Registry (GitHub Container Registry, Docker Hub, or AWS ECR)
- Kubernetes Cluster (EKS, GKE, AKS, or local cluster)
- Database (PostgreSQL 15+)
- Cache (Redis 7+)
- Message Queue (Apache Kafka)
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Load Balancer β β Ingress β β Django App β
β (Nginx) βββββΆβ Controller βββββΆβ (3 replicas) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ β
β PostgreSQL ββββββββββββββββ
β Database β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Redis Cache β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Apache Kafka β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Go Service β
β (Data Proc.) β
βββββββββββββββββββ
# Clone repository
git clone <repository-url>
cd wanna-fit
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\Activate.ps1 # Windows
# Install dependencies
pip install -r requirements.txt
# Run migrations
python manage.py migrate
# Start development server
python run_dev.py# Deploy to staging
./scripts/deploy.sh staging
# Or using PowerShell on Windows
.\scripts\deploy.ps1 -Environment staging# Deploy to production
./scripts/deploy.sh production
# Or using PowerShell on Windows
.\scripts\deploy.ps1 -Environment production# Build development image
docker build --target development -t wanna-fit:dev .
# Build staging image
docker build --target staging -t wanna-fit:staging .
# Build production image
docker build --target production -t wanna-fit:prod .# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downkubectl create namespace wanna-fit-prod# Create secrets (replace with actual values)
kubectl create secret generic wanna-fit-prod-secret \
--from-literal=SECRET_KEY="your-secret-key" \
--from-literal=DB_PASSWORD="your-db-password" \
--from-literal=EMAIL_HOST_USER="your-email" \
--from-literal=EMAIL_HOST_PASSWORD="your-email-password" \
-n wanna-fit-prod# Deploy PostgreSQL
kubectl apply -f k8s/postgres.yaml
# Deploy Redis
kubectl apply -f k8s/redis.yaml
# Deploy Kafka
kubectl apply -f k8s/kafka.yaml# Deploy Django app
kubectl apply -f k8s/production/django-app.yaml
# Deploy ingress
kubectl apply -f k8s/production/ingress.yaml# Deploy Prometheus
kubectl apply -f k8s/monitoring/prometheus.yaml
# Deploy Grafana
kubectl apply -f k8s/monitoring/grafana.yamlThe CI/CD pipeline includes:
-
Testing Phase
- Unit tests with coverage
- Security scanning
- Code quality checks (linting, formatting)
-
Build Phase
- Docker image building
- Multi-architecture support
- Image scanning for vulnerabilities
-
Deploy Phase
- Staging deployment (on develop branch)
- Production deployment (on main branch)
- Health checks and smoke tests
# Deploy specific version
./scripts/deploy.sh production v1.2.3
# Rollback deployment
kubectl rollout undo deployment/wanna-fit-web-prod -n wanna-fit-prod- Liveness:
GET /health/live/ - Readiness:
GET /health/ready/ - Health:
GET /health/
- Application Metrics: Available at
/metrics/ - Prometheus: Scrapes metrics every 30 seconds
- Grafana: Dashboard at
http://grafana-service:3000
- Application Logs: Available in pod logs
- Centralized Logging: Configure with ELK stack or similar
-
Secrets Management
- Use Kubernetes secrets
- Rotate secrets regularly
- Never commit secrets to repository
-
Network Security
- Use TLS/SSL certificates
- Configure network policies
- Enable firewall rules
-
Application Security
- Enable Django security middleware
- Use HTTPS in production
- Configure CORS properly
# Required environment variables
SECRET_KEY=your-secret-key
DATABASE_URL=postgresql://user:pass@host:port/db
REDIS_URL=redis://host:port/db
ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
DEBUG=False-
Pod Not Starting
kubectl describe pod <pod-name> -n wanna-fit-prod kubectl logs <pod-name> -n wanna-fit-prod
-
Database Connection Issues
kubectl exec -it <pod-name> -n wanna-fit-prod -- python manage.py dbshell
-
Cache Issues
kubectl exec -it redis-pod -n wanna-fit-prod -- redis-cli ping
-
Horizontal Scaling
kubectl scale deployment wanna-fit-web-prod --replicas=5 -n wanna-fit-prod
-
Resource Limits
- Adjust CPU/memory limits in deployment manifests
- Monitor resource usage with Prometheus
-
Database Optimization
- Enable connection pooling
- Use read replicas for read-heavy workloads
The HPA automatically scales pods based on:
- CPU utilization (target: 70%)
- Memory utilization (target: 80%)
- Custom metrics (if configured)
# Update resource limits
kubectl patch deployment wanna-fit-web-prod -n wanna-fit-prod -p '{"spec":{"template":{"spec":{"containers":[{"name":"django","resources":{"limits":{"cpu":"2000m","memory":"2Gi"}}}]}}}}'# Create backup
kubectl exec -it postgres-pod -n wanna-fit-prod -- pg_dump -U postgres wanna_fit > backup.sql
# Restore backup
kubectl exec -i postgres-pod -n wanna-fit-prod -- psql -U postgres wanna_fit < backup.sql# Backup media files
kubectl exec -it <pod-name> -n wanna-fit-prod -- tar -czf /tmp/media-backup.tar.gz /app/media
# Copy backup
kubectl cp <pod-name>:/tmp/media-backup.tar.gz ./media-backup.tar.gz -n wanna-fit-prodFor deployment issues:
- Check the logs:
kubectl logs <pod-name> -n wanna-fit-prod - Verify configuration:
kubectl describe <resource> -n wanna-fit-prod - Test connectivity:
kubectl exec -it <pod-name> -n wanna-fit-prod -- curl localhost:8000/health/
- Set up monitoring alerts
- Configure log aggregation
- Implement blue-green deployments
- Add chaos engineering tests
- Set up disaster recovery procedures