# K8s Game 2048 A Kubernetes deployment of the classic 2048 game using Knative Serving with Istio service mesh and nginx ingress for SSL termination. ## Features - **Knative Serving**: Serverless deployment with scale-to-zero capability - **Istio Service Mesh**: Advanced traffic management and observability - **nginx Ingress**: SSL termination and traffic routing - **Multi-environment**: Development, Staging, and Production deployments - **Custom Domains with SSL**: Environment-specific HTTPS domains - **GitOps Workflow**: Complete CI/CD pipeline with GitHub Actions ## Environments - **Development**: `https://${DEV_CANONICAL_DOMAIN}` - **Staging**: `https://${STAGING_CANONICAL_DOMAIN}` - **Production**: `https://${PROD_CANONICAL_DOMAIN}` ## πŸ”„ CI/CD Pipeline This project features a fully automated CI/CD pipeline with: - **Automated Deployments**: Push to `develop` β†’ auto-deploy to dev β†’ auto-promote to staging β†’ auto-promote to production - **Comprehensive Testing**: Smoke tests after each deployment - **Manual Controls**: Override any step with manual workflows - **Zero-downtime Deployments**: Blue-green strategy for production - **Security**: Webhook signature validation and environment-specific secrets ### Quick Actions | Action | Command | |--------|---------| | πŸ“Š Check Status | Actions β†’ "Deployment Status Check" | | πŸš€ Deploy to Prod | Actions β†’ "Deploy to Production" (type "DEPLOY") | | ⬆️ Promote to Prod | Actions β†’ "Promote to Production" (type "PROMOTE") | | πŸ§ͺ Run Tests | Actions β†’ "Smoke Tests" | πŸ“š **[Full Pipeline Documentation](docs/WORKFLOWS.md)** | πŸš€ **[Quick Reference](docs/WORKFLOW_QUICK_REFERENCE.md)** ## Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Internet β”‚ β”‚ nginx β”‚ β”‚ Istio β”‚ β”‚ Knative β”‚ β”‚ │───▢│ Ingress │───▢│ Gateway │───▢│ Service β”‚ β”‚ β”‚ β”‚ (SSL Term.) β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ cert-managerβ”‚ β”‚ 2048 Game β”‚ β”‚ Let's Encryptβ”‚ β”‚ Container β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Quick Start ### Prerequisites - Kubernetes cluster (1.21+) with k3s or similar - Knative Serving installed - Istio service mesh installed - nginx ingress controller installed - cert-manager for SSL certificates - kubectl configured - Domain DNS configured to point to your cluster IP ### Installation 1. Clone the repository: ```bash git clone https://github.com/${GITHUB_REPOSITORY}.git cd k8s-game-2048 ``` 2. Deploy all environments: ```bash ./scripts/deploy.sh all ``` 3. Or deploy a specific environment: ```bash ./scripts/deploy.sh dev # Development only ./scripts/deploy.sh staging # Staging only ./scripts/deploy.sh prod # Production only ``` 3. Deploy to staging: ```bash kubectl apply -f manifests/staging/ ``` 4. Deploy to production: ```bash kubectl apply -f manifests/prod/ ``` ## πŸ“ Project Structure ``` k8s-game-2048/ β”œβ”€β”€ README.md β”œβ”€β”€ Dockerfile β”œβ”€β”€ .github/ β”‚ └── workflows/ # CI/CD Pipeline β”‚ β”œβ”€β”€ build-image.yml # Build & push Docker images β”‚ β”œβ”€β”€ deploy-dev.yml # Development deployment β”‚ β”œβ”€β”€ deploy-staging.yml # Staging deployment β”‚ β”œβ”€β”€ deploy-prod.yml # Production deployment β”‚ β”œβ”€β”€ smoke-test.yml # Post-deployment testing β”‚ β”œβ”€β”€ auto-promote.yml # Auto dev β†’ staging promotion β”‚ β”œβ”€β”€ promote-to-production.yml # Auto/manual staging β†’ prod β”‚ └── deployment-status.yml # Environment health checks β”œβ”€β”€ docs/ β”‚ β”œβ”€β”€ WORKFLOWS.md # Complete pipeline documentation β”‚ β”œβ”€β”€ WORKFLOW_QUICK_REFERENCE.md # Quick action guide β”‚ β”œβ”€β”€ SETUP.md # Environment setup guide β”‚ β”œβ”€β”€ ENVIRONMENT.md # Environment configuration β”‚ └── WEBHOOK_DEPLOYMENT.md # Webhook handler setup β”œβ”€β”€ manifests/ β”‚ β”œβ”€β”€ dev/ # Development Kubernetes manifests β”‚ β”œβ”€β”€ staging/ # Staging Kubernetes manifests β”‚ β”œβ”€β”€ prod/ # Production Kubernetes manifests β”‚ └── webhook/ # Webhook handler manifests β”œβ”€β”€ scripts/ # Setup and deployment scripts └── src/ # 2048 game source code β”œβ”€β”€ index.html β”œβ”€β”€ style.css └── script.js ``` ## Deployment The application uses Knative Serving with the following features: - **Scale to Zero**: Automatically scales down to 0 when not in use - **Auto-scaling**: Scales up based on incoming requests - **Blue-Green Deployments**: Safe deployment strategy with traffic splitting - **Custom Domains**: Environment-specific domain mapping ## Monitoring Each environment includes: - Knative Service status monitoring - Request metrics via Knative - Custom domain health checks ## πŸ”’ Security & Privacy This repository is **PII-free** and production-ready: - βœ… **No hardcoded emails, domains, or personal information** - βœ… **All configuration via environment variables** - βœ… **Secrets managed via `.env` files and GitHub secrets** - βœ… **Generic templates that work for any domain/organization** ### Quick Setup 1. **Clone and configure:** ```bash git clone https://github.com/${GITHUB_REPOSITORY}.git cd k8s-game-2048 cp .env.example .env # Edit .env with your actual values ``` 2. **Apply your configuration:** ```bash ./scripts/cleanup-pii.sh ``` 3. **Set GitHub secrets for CI/CD:** - `DEV_DOMAIN`, `STAGING_DOMAIN`, `PROD_DOMAIN` - `WEBHOOK_SECRET` - Webhook URLs for each environment ## Contributing 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add some amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.