This repository contains both the Python guestbook application source code and its GitOps deployment configuration using Kustomize and ArgoCD.
src/- Python guestbook application source codeapp.py- Main Flask applicationDockerfile.alpine- Container build configurationrequirements.txt- Python dependenciesstatic/- Static files (CSS, JS, images)
apps/guestbook/base/- Kustomize configuration for deploymentguestbook-*- Main application manifests (deployment, service, configmap)nginx-*- Static file server manifests (deployment, service, configmap)ingress.yaml- Traefik ingress configuration (shared)cert-issuer.yaml- SSL certificate issuer configurationkustomization.yaml- Kustomize orchestration file
argocd/- ArgoCD Application definitions (includes PostgreSQL Helm chart).github/workflows/- GitHub Actions for automated CI/CD
- Code Change: Developer pushes changes to
src/folder - Build Trigger: GitHub Actions detects changes in
src/and starts build - Docker Build: Application is containerized using
src/Dockerfile.alpine - Image Push: Docker image is pushed to GitHub Container Registry
- GitOps Update: Same workflow updates the image tag in
kustomization.yaml - ArgoCD Sync: ArgoCD detects GitOps changes and deploys to Kubernetes
- Database: PostgreSQL is deployed as a separate Helm chart via ArgoCD
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β guestbook namespace β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β π App β β π Nginx β β π PostgreSQL β β
β β guestbook β β Static β β Database β β
β β deployment β β Server β β (Helm) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β β
β β β β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β guestbook β β nginx-staticβ β postgresql β β
β β service β β service β β service β β
β β :80 β β :80 β β :5432 β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β
β βββββββββββββββββββββ΄βββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β π Traefik Ingress β β
β β β β
β β Routes: β β
β β β’ / β guestbook-service (Python app) β β
β β β’ /static β nginx-static-service (Static files) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β π SSL/TLS β β
β β β
β βββββββββββββββ β βββββββββββββββ β
β β Let's β β β Certificate β β
β β Encrypt β β β guestbook- β β
β β Issuer β β β tls-cert β β
β βββββββββββββββ β βββββββββββββββ β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β
βοΈ Internet (HTTPS)
gb-heg.duckdns.org
guestbook-deployment:
βββ π¦ Container: guestbook
β βββ π Port: 5000
β βββ π Environment Variables:
β β βββ DB_HOST=postgresql
β β βββ DB_PORT=5432
β β βββ DB_NAME=guestbook
β β βββ DB_USER=guestbook
β β βββ DB_PASS=<from postgresql secret>
β β βββ GUESTBOOK_SERVICE=postgres
β βββ π₯ Health Checks:
β β βββ Startup Probe: /health (10s delay, 5s interval, 6 failures = 30s max)
β β βββ Liveness Probe: /health (30s delay, 10s interval)
β β βββ Readiness Probe: /ready (5s delay, 5s interval)
β βββ π― Endpoints:
β βββ /health - Application liveness check
β βββ /ready - Database connectivity + readiness
βββ π Replicas: 2
βββ π Resources: 100m CPU, 128Mi-256Mi RAM
nginx-static-deployment:
βββ π Init Container (static-extractor):
β βββ π¦ Image: same as guestbook
β βββ π Copies: /app/static/* β /shared/static/
β βββ πΎ Volume: static-volume (emptyDir)
βββ π¦ Main Container (nginx):
β βββ π¦ Image: nginx:1.25-alpine
β βββ π Port: 80
β βββ π Serves: /usr/share/nginx/html/static
β βββ βοΈ Config: nginx-config ConfigMap
β βββ π₯ Health Check: /health
βββ π Replicas: 2
βββ π Resources: 50m CPU, 64Mi-128Mi RAM
postgresql (Helm Chart):
βββ π Chart: bitnami/postgresql v12.12.10
βββ ποΈ Database: guestbook
βββ π€ User: guestbook
βββ π Password: guestbook123 (in secret)
βββ πΎ Storage: 2Gi PVC
βββ π Port: 5432
βββ π Replicas: 1 (primary)
βββ π Resources: 250m CPU, 256Mi-512Mi RAM
cert-manager setup:
βββ π’ Issuer: letsencrypt-guestbook-issuer
β βββ π§ Email: your-email@example.com
β βββ π ACME Server: Let's Encrypt v2
β βββ π‘οΈ Challenge: HTTP-01 via Traefik
βββ π Certificate: guestbook-tls-cert
β βββ π Domain: gb-heg.duckdns.org
β βββ π Auto-renewal: Yes
β βββ π Secret: guestbook-tls-cert
βββ π Ingress: TLS termination at Traefik
1. π User visits https://gb-heg.duckdns.org/
2. π DNS resolves to Traefik LoadBalancer
3. π Traefik terminates SSL using guestbook-tls-cert
4. π£οΈ Traefik routes based on path:
βββ /static/* β nginx-static-service:80
βββ /* β guestbook-service:80
5. π Python app processes request
6. π App queries PostgreSQL if needed
7. π€ Response sent back to user
1. π Pod starts with init container
2. π¦ Init container uses guestbook image
3. π Copies /app/static/* to shared volume
4. β
Init container completes
5. π Nginx container starts
6. π Mounts shared volume at /usr/share/nginx/html/static
7. π Nginx serves files with caching headers
1. π Guestbook app starts
2. π Reads environment variables
3. π Connects to postgresql:5432
4. π Uses credentials from postgresql secret
5. ποΈ Creates/uses guestbook database
6. π¬ Stores guestbook entries
The guestbook application uses these environment variables to connect to PostgreSQL:
DB_HOST- PostgreSQL service hostname (postgresql)DB_PORT- PostgreSQL port (5432)DB_NAME- Database name (guestbook)DB_USER- Database username (guestbook)DB_PASS- Database password (from PostgreSQL secret)GUESTBOOK_SERVICE- Backend service type (postgres)
GitOps is a deployment methodology that uses Git as the single source of truth for infrastructure and application configuration. Key principles:
- π Declarative: Everything is described declaratively (YAML manifests)
- π Versioned: All changes are tracked in Git history
- π Automated: Deployments happen automatically when Git changes
- π₯ Observable: Current state vs desired state is always visible
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β π± Developer β β π GitHub β β βοΈ Kubernetes β
β Source Code β β Actions β β Cluster β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β 1. git push src/ β β
βΌ β β
βββββββββββββββββββ β β
β π Monorepo β β β
β βββ src/ β β β
β βββ apps/ β β β
β βββ argocd/ β β β
βββββββββββββββββββ β β
β β β
β 2. trigger on src/ β β
βΌ β β
ββββββββββββββββββββββββΆβ β
β 3. build & push β
βΌ β
βββββββββββββββββββ β
β π¦ GitHub β β
β Container β β
β Registry β β
βββββββββββββββββββ β
β β
β 4. update same repo β
βΌ β
βββββββββββββββββββ β
β π GitOps β β
β Config β β
β (same repo) β β
βββββββββββββββββββ β
β β
β 5. ArgoCD sync β
βΌ β
βββββββββββββββββββ β
β π ArgoCD β β
β Controller β β
βββββββββββββββββββ β
β β
β 6. deploy β
βΌ β
ββββββββββββββββββββββββΆβ
β
βββββββββββββββββββ
β π Guestbook β
β π Nginx β
β π PostgreSQL β
βββββββββββββββββββ
- Static Files: Served by nginx (fast, cached, CDN-ready)
- Dynamic Content: Handled by Python app (business logic)
- Data Storage: PostgreSQL (ACID compliance, relationships)
- Independent Scaling: Each component scales based on load
- Resource Optimization: nginx uses less resources than Python for static files
- Caching Strategy: Static files cached at nginx level
- Namespace Isolation: All components in dedicated namespace
- Secret Management: Database credentials managed by Kubernetes
- TLS Termination: SSL handled at ingress level
- Least Privilege: Each component has minimal required permissions
- ArgoCD installed and running
- cert-manager installed for SSL/TLS certificates
- Traefik ingress controller
- DNS record pointing
gb-heg.duckdns.orgto your cluster
-
Update Email in cert-issuer.yaml:
# Edit apps/guestbook/base/cert-issuer.yaml # Change: email: your-email@example.com
-
Update Repository Name in kustomization.yaml:
# Edit apps/guestbook/base/kustomization.yaml # Change: ghcr.io/your-username/guestbook-gitops
-
Enable GitHub Actions:
# Make sure your repository has Actions enabled # The workflow will automatically trigger on pushes to src/
-
Apply ArgoCD applications:
kubectl apply -f argocd/app-of-apps.yaml
-
Verify SSL certificate:
kubectl get certificate -n guestbook kubectl describe certificate guestbook-tls-cert -n guestbook
ArgoCD will automatically deploy PostgreSQL (via Helm), the guestbook application, and nginx for static files, all in the guestbook namespace.
The setup includes automatic SSL/TLS certificates via Let's Encrypt:
- Domain:
gb-heg.duckdns.org - Issuer: Let's Encrypt ACME HTTP-01 challenge
- Certificate: Automatically managed by cert-manager
- Ingress: Routes
/staticto nginx, everything else to guestbook app
PostgreSQL is deployed directly as a Helm chart with these settings:
- Chart:
bitnami/postgresqlversion12.12.10 - Database:
guestbook - Username:
guestbook - Password:
guestbook(stored in auto-generated secret) - Storage: 2Gi persistent volume
Image tags are automatically updated by GitHub Actions from the source repository. The workflow updates the apps/guestbook/base/kustomization.yaml file with new image tags based on commit hashes.
The base directory uses prefixed filenames for clarity:
guestbook-*: Main Python application resourcesnginx-*: Static file server resourcescert-issuer.yaml: SSL certificate managementkustomization.yaml: Kustomize orchestration
- Database credentials are managed by the PostgreSQL Helm chart
- The guestbook app reads the password from the
postgresqlsecret created by Helm - All secrets are base64 encoded and stored in Kubernetes
# Deploy everything
kubectl apply -f argocd/app-of-apps.yaml
# Check certificate status
kubectl get certificate guestbook-tls-cert -n guestbook
kubectl describe certificate guestbook-tls-cert -n guestbook
# Check issuer status
kubectl get issuer letsencrypt-guestbook-issuer -n guestbook
# Check all guestbook resources
kubectl get all -n guestbookIf the certificate doesn't get issued:
# Check cert-manager logs
kubectl logs -n cert-manager -l app=cert-manager
# Check certificate request
kubectl get certificaterequests -n guestbook
kubectl describe certificaterequest <name> -n guestbook
# Check challenges
kubectl get challenges -n guestbook# 1. Check what ArgoCD creates first
kubectl get applications -n argocd
# 2. Watch resources being created
kubectl get events -n guestbook --sort-by='.lastTimestamp'
# 3. Understand service discovery
kubectl exec -n guestbook deployment/guestbook -- nslookup postgresql# Scale nginx independently
kubectl scale deployment nginx-static -n guestbook --replicas=3
# Scale guestbook app
kubectl scale deployment guestbook -n guestbook --replicas=4
# Watch resource usage
kubectl top pods -n guestbook# Check certificate details
kubectl get certificate guestbook-tls-cert -n guestbook -o yaml
# Force certificate renewal (for testing)
kubectl delete certificate guestbook-tls-cert -n guestbook
# ArgoCD will recreate it automatically
# Check certificate expiry
kubectl describe certificate guestbook-tls-cert -n guestbook# 1. Make a change to image tag in kustomization.yaml
# 2. Commit and push to Git
# 3. Watch ArgoCD detect and sync the change
kubectl get applications -n argocd -w
# Check sync status
kubectl describe application guestbook -n argocd- Deployments: Rolling updates, replica management
- Services: Service discovery, load balancing
- Ingress: HTTP routing, TLS termination
- ConfigMaps: Configuration management
- Secrets: Sensitive data storage
- Namespaces: Resource isolation
- Init Containers: Setup tasks before main container
- ArgoCD: GitOps continuous delivery
- Kustomize: Kubernetes configuration management
- Helm: Package manager for Kubernetes
- cert-manager: Automatic SSL certificate management
- Traefik: Modern HTTP reverse proxy and load balancer
- PostgreSQL: Relational database
- nginx: High-performance web server
- ποΈ Infrastructure as Code: Everything defined in YAML
- π GitOps Workflow: Git as single source of truth
- π¦ Container Security: Non-root containers, resource limits
- π― Separation of Concerns: Static vs dynamic content
- π Observability: Health checks, monitoring endpoints
- π Security: TLS, secrets management, namespace isolation
- Implement Health Endpoints: Add
/healthand/readyendpoints to your Flask app (seesrc/health_endpoints.pyfor reference) - Experiment with the configuration: Try changing resource limits, replica counts
- Add monitoring: Integrate Prometheus/Grafana for metrics
- Implement CI/CD: Test the complete workflow by modifying code in
src/ - Add more environments: Create staging/production overlays
- Database migrations: Add init containers for database schema
- Backup strategies: Implement PostgreSQL backup solutions
- Monitoring and alerting: Add health checks and alert rules
Your Flask application should implement these endpoints for proper Kubernetes health checking:
@app.route('/health')
def health_check():
# Liveness probe - is the app running?
return {"status": "healthy"}, 200
@app.route('/ready')
def readiness_check():
# Readiness probe - can the app serve traffic?
# Should check database connectivity
return {"status": "ready", "database": "connected"}, 200- Startup Probe: Kubernetes waits up to 30 seconds for app to start
- Liveness Probe: Kubernetes restarts container if /health fails
- Readiness Probe: Kubernetes stops sending traffic if /ready fails
See src/health_endpoints.py for a complete implementation example.