# BSPDS Production Kubernetes Deployment > **Warning**: These instructions are untested and theoretical, written from the top of Lewis' head. They may contain errors or omissions. This warning will be removed once the guide has been verified. This guide covers deploying BSPDS on a production multi-node Kubernetes cluster with high availability, auto-scaling, and proper secrets management. ## Architecture Overview ``` ┌─────────────────────────────────────────────────┐ │ Kubernetes Cluster │ │ │ Internet ──────►│ Ingress Controller (nginx/traefik) │ │ │ │ │ ▼ │ │ ┌─────────────┐ │ │ │ Service │◄── HPA (2-10 replicas) │ │ └──────┬──────┘ │ │ │ │ │ ┌────┴────┐ │ │ ▼ ▼ │ │ ┌─────┐ ┌─────┐ │ │ │BSPDS│ │BSPDS│ ... (pods) │ │ └──┬──┘ └──┬──┘ │ │ │ │ │ │ ▼ ▼ │ │ ┌──────────────────────────────────────┐ │ │ │ PostgreSQL │ MinIO │ Valkey │ │ │ │ (HA/Operator)│ (StatefulSet) │ (Sentinel) │ │ └──────────────────────────────────────┘ │ └─────────────────────────────────────────────────┘ ``` ## Prerequisites - Kubernetes cluster (1.30+) with at least 3 nodes (1.34 is current stable) - `kubectl` configured to access your cluster - `helm` 3.x installed - Storage class that supports `ReadWriteOnce` (for databases) - Ingress controller installed (nginx-ingress or traefik) - cert-manager installed for TLS certificates ### Quick Prerequisites Setup If you need to install prerequisites: ```bash # Install nginx-ingress (chart v4.14.1 - December 2025) helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update helm install ingress-nginx ingress-nginx/ingress-nginx \ --namespace ingress-nginx --create-namespace \ --version 4.14.1 # Install cert-manager (v1.19.2 - December 2025) helm repo add jetstack https://charts.jetstack.io helm repo update helm install cert-manager jetstack/cert-manager \ --namespace cert-manager --create-namespace \ --version v1.19.2 \ --set installCRDs=true ``` --- ## 1. Create Namespace ```bash kubectl create namespace bspds kubectl config set-context --current --namespace=bspds ``` ## 2. Create Secrets Generate secure passwords and secrets: ```bash # Generate secrets DB_PASSWORD=$(openssl rand -base64 32) MINIO_PASSWORD=$(openssl rand -base64 32) JWT_SECRET=$(openssl rand -base64 48) DPOP_SECRET=$(openssl rand -base64 48) MASTER_KEY=$(openssl rand -base64 48) # Create Kubernetes secrets kubectl create secret generic bspds-db-credentials \ --from-literal=username=bspds \ --from-literal=password="$DB_PASSWORD" kubectl create secret generic bspds-minio-credentials \ --from-literal=root-user=minioadmin \ --from-literal=root-password="$MINIO_PASSWORD" kubectl create secret generic bspds-secrets \ --from-literal=jwt-secret="$JWT_SECRET" \ --from-literal=dpop-secret="$DPOP_SECRET" \ --from-literal=master-key="$MASTER_KEY" # Save secrets locally (KEEP SECURE!) echo "DB_PASSWORD=$DB_PASSWORD" > secrets.txt echo "MINIO_PASSWORD=$MINIO_PASSWORD" >> secrets.txt echo "JWT_SECRET=$JWT_SECRET" >> secrets.txt echo "DPOP_SECRET=$DPOP_SECRET" >> secrets.txt echo "MASTER_KEY=$MASTER_KEY" >> secrets.txt chmod 600 secrets.txt ``` ## 3. Deploy PostgreSQL ### Option A: CloudNativePG Operator (Recommended for HA) ```bash # Install CloudNativePG operator (v1.28.0 - December 2025) kubectl apply --server-side -f \ https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.28/releases/cnpg-1.28.0.yaml # Wait for operator kubectl wait --for=condition=available --timeout=120s \ deployment/cnpg-controller-manager -n cnpg-system ``` ```bash cat < **Note**: If your BSPDS image doesn't have a `--migrate-only` flag, you can skip this step. The app will run migrations on first startup. Alternatively, build a separate migration image with `sqlx-cli` installed. ## 8. Deploy BSPDS Application ```bash cat < backup-$(date +%Y%m%d).sql ``` ### Run Migrations If you have a migration Job defined, you can re-run it: ```bash # Delete old job first (if exists) kubectl delete job bspds-migrate -n bspds --ignore-not-found # Re-apply the migration job from step 7 # Or simply restart the deployment - BSPDS runs migrations on startup kubectl rollout restart deployment/bspds -n bspds ``` --- ## Troubleshooting ### Pod Won't Start ```bash kubectl describe pod -l app=bspds -n bspds kubectl logs -l app=bspds -n bspds --previous ``` ### Database Connection Issues ```bash # Test connectivity from a debug pod kubectl run debug --rm -it --restart=Never --image=postgres:18-alpine -- \ psql "postgres://bspds:PASSWORD@bspds-db-rw:5432/pds" -c "SELECT 1" ``` ### Certificate Issues ```bash kubectl describe certificate bspds-tls -n bspds kubectl describe certificaterequest -n bspds kubectl logs -l app.kubernetes.io/name=cert-manager -n cert-manager ``` ### View Resource Usage ```bash kubectl top pods -n bspds kubectl top nodes ```