GKE Deployment Guide - Django Backend
Project: CODITECT License Management Platform Version: v1.0.7 Deployed: December 28, 2025 Cluster: coditect-citus-dev (GKE in coditect-citus-prod project) Namespace: coditect-dev
Current Deployment Status
| Component | Status | Replicas | Image Version |
|---|---|---|---|
| Django Backend | Running | 2/2 | v1.0.7 |
| Celery Worker | Running | 1/1 | v1.0.7 |
| Redis (Memorystore) | Running | N/A | Managed |
| Cloud SQL (PostgreSQL) | Running | N/A | Managed |
Health Checks: /health/ returning 200 OK
1. Prerequisites
GCP Resources Required
- GKE cluster with Workload Identity enabled
- Artifact Registry repository for Docker images
- Cloud SQL PostgreSQL instance (private IP)
- Redis Memorystore instance (private IP)
- Secret Manager secrets configured
CLI Tools
gcloud version # Google Cloud SDK
kubectl version --client # Kubernetes CLI
docker version # Docker
Authenticate
gcloud auth login
gcloud config set project coditect-citus-prod
gcloud container clusters get-credentials coditect-citus-dev --region us-central1
2. Build Docker Image
cd /path/to/coditect-cloud-infra
# Build for linux/amd64 (GKE compatibility)
docker build --platform linux/amd64 \
-t us-central1-docker.pkg.dev/coditect-citus-prod/coditect-docker/django-backend:VERSION \
-f Dockerfile .
3. Push to Artifact Registry
gcloud auth configure-docker us-central1-docker.pkg.dev
docker push us-central1-docker.pkg.dev/coditect-citus-prod/coditect-docker/django-backend:VERSION
4. Create Kubernetes Secrets
# Database credentials
kubectl create secret generic database-credentials \
-n coditect-dev \
--from-literal=url='postgresql://USER:PASS@10.67.0.3:5432/coditect'
# Redis credentials
kubectl create secret generic redis-credentials \
-n coditect-dev \
--from-literal=url='redis://10.159.63.195:6378'
# Django secrets
kubectl create secret generic django-secrets \
-n coditect-dev \
--from-literal=secret-key='YOUR_SECRET_KEY'
5. Deploy to GKE
kubectl apply -f kubernetes/base/configmap.yaml -n coditect-dev
kubectl apply -f kubernetes/base/deployment.yaml -n coditect-dev
kubectl apply -f kubernetes/base/service.yaml -n coditect-dev
# Verify rollout
kubectl rollout status deployment/django-backend -n coditect-dev --timeout=120s
6. Verify Deployment
# Check pods
kubectl get pods -n coditect-dev
# Check logs
kubectl logs -n coditect-dev -l app=django-backend --tail=20
# Test health endpoint
kubectl port-forward -n coditect-dev svc/django-backend 8000:80 &
curl http://localhost:8000/health/
7. Configuration Reference
Environment Variables (ConfigMap)
| Variable | Value | Description |
|---|---|---|
| DJANGO_DEBUG | False | Debug mode |
| DJANGO_ALLOWED_HOSTS | * | Allowed hosts |
| DATABASE_HOST | 10.67.0.3 | Cloud SQL IP |
| REDIS_HOST | 10.159.63.195 | Memorystore IP |
| LOG_LEVEL | INFO | Logging level |
Secrets Required
| Secret | Key | Description |
|---|---|---|
| database-credentials | url | PostgreSQL URL |
| redis-credentials | url | Redis URL |
| django-secrets | secret-key | Django SECRET_KEY |
8. Issues Fixed During Deployment
| Issue | Error | Fix |
|---|---|---|
| Logging permissions | PermissionError: /app/logs | Console-only logging |
| Missing Celery | No attribute 'celery' | Created celery.py |
| File permissions | PermissionError .py files | chmod 644 |
| Directory permissions | ModuleNotFoundError | chmod 755 |
| ALLOWED_HOSTS | DisallowedHost | DJANGO_ALLOWED_HOSTS |
| Health endpoint | 404 on /health/ | Added health_check view |
| HTTPS redirect | 301 on health check | SECURE_REDIRECT_EXEMPT |
9. Operations
# Scale replicas
kubectl scale deployment/django-backend -n coditect-dev --replicas=3
# Rolling update
kubectl apply -f kubernetes/base/deployment.yaml -n coditect-dev
# Rollback
kubectl rollout undo deployment/django-backend -n coditect-dev
# Restart
kubectl rollout restart deployment/django-backend -n coditect-dev
10. Next Steps
- Configure Ingress/LoadBalancer
- Set up SSL/TLS certificate
- Configure api.coditect.ai domain
- Set up Cloud KMS for license signing
- Configure Identity Platform OAuth2
- Add Prometheus/Grafana monitoring
Version History: v1.0.0 → v1.0.7 (7 iterations fixing deployment issues) Last Updated: December 28, 2025