This page walks through running LeafLock on Kubernetes with production-ready configuration, monitoring, and scaling guidance.
☸️ Cloud-Native Architecture
LeafLock Kubernetes Components:
Frontend: React app deployment with Nginx
Backend: Go application with horizontal scaling
Database: PostgreSQL with persistent storage
Cache: Redis cluster for high availability
Ingress: HTTPS termination and routing
Secrets: Encrypted environment variables
Benefits:
Auto-scaling based on load
High availability and fault tolerance
Rolling updates with zero downtime
Resource management and monitoring
Multi-environment support
☸️ Kubernetes Cluster
Kubernetes 1.24+ cluster
kubectl configured
Cluster admin permissions
LoadBalancer support (cloud provider)
📦 Additional Tools
Helm 3.0+ package manager
Container registry access
SSL certificate management
Persistent volume support
├── Chart.yaml # Helm chart metadata
├── values.yaml # Default configuration values
├── values-prod.yaml # Production overrides
│ │ ├── deployment.yaml # Frontend deployment
│ │ ├── service.yaml # Frontend service
│ │ └── configmap.yaml # Frontend config
│ │ ├── deployment.yaml # Backend deployment
│ │ ├── service.yaml # Backend service
│ │ └── hpa.yaml # Horizontal Pod Autoscaler
│ │ ├── statefulset.yaml # PostgreSQL StatefulSet
│ │ ├── service.yaml # Database service
│ │ └── pvc.yaml # Persistent volume claim
│ │ ├── deployment.yaml # Redis deployment
│ │ └── service.yaml # Redis service
│ ├── ingress.yaml # Ingress controller
│ ├── secrets.yaml # Encrypted secrets
│ └── _helpers.tpl # Template helpers
└── charts/ # Dependency charts
app.kubernetes.io/name : leaflock
postgres-password : {{ .Values.database.password | b64enc }}
redis-password : {{ .Values.redis.password | b64enc }}
jwt-secret : {{ .Values.backend.jwtSecret | b64enc }}
encryption-key : {{ .Values.backend.encryptionKey | b64enc }}
admin-password : {{ .Values.admin.password | b64enc }}
🗄️ PostgreSQL StatefulSet
StatefulSet for Persistent Storage:
Ordered deployment and scaling
Persistent volume claims
Stable network identities
Automated backup integration
image : postgres:15-alpine
- name : POSTGRES_PASSWORD
mountPath : /var/lib/postgresql/data
accessModes : [ " ReadWriteOnce " ]
storageClassName : fast-ssd # Use appropriate storage class
⚡ Go Backend Deployment
Deployment Features:
Horizontal Pod Autoscaler
Rolling update strategy
Health check probes
Resource limits and requests
Environment-based configuration
replicas : {{ .Values.backend.replicas }}
image : " {{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag }} "
imagePullPolicy : {{ .Values.backend.image.pullPolicy }}
value : " postgres://postgres:$(POSTGRES_PASSWORD)@postgres:5432/notes?sslmode=require "
- name : POSTGRES_PASSWORD
- name : SERVER_ENCRYPTION_KEY
value : {{ .Values.frontend.corsOrigins | quote }}
memory : {{ .Values.backend.resources.requests.memory }}
cpu : {{ .Values.backend.resources.requests.cpu }}
memory : {{ .Values.backend.resources.limits.memory }}
cpu : {{ .Values.backend.resources.limits.cpu }}
allowPrivilegeEscalation : false
readOnlyRootFilesystem : true
replicas : {{ .Values.frontend.replicas }}
image : " {{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }} "
imagePullPolicy : {{ .Values.frontend.image.pullPolicy }}
- name : BACKEND_INTERNAL_URL
value : " http://backend:8080 "
memory : {{ .Values.frontend.resources.requests.memory }}
cpu : {{ .Values.frontend.resources.requests.cpu }}
memory : {{ .Values.frontend.resources.limits.memory }}
cpu : {{ .Values.frontend.resources.limits.cpu }}
allowPrivilegeEscalation : false
readOnlyRootFilesystem : true
🌐 Ingress Controller Setup
HTTPS Termination and Routing:
Automatic SSL certificate management
Path-based routing for frontend/backend
Load balancing across pod replicas
Rate limiting and security headers
apiVersion : networking.k8s.io/v1
kubernetes.io/ingress.class : nginx
cert-manager.io/cluster-issuer : letsencrypt-prod
nginx.ingress.kubernetes.io/ssl-redirect : " true "
nginx.ingress.kubernetes.io/force-ssl-redirect : " true "
nginx.ingress.kubernetes.io/use-regex : " true "
nginx.ingress.kubernetes.io/rate-limit : " 100 "
nginx.ingress.kubernetes.io/rate-limit-window : " 1m "
nginx.ingress.kubernetes.io/configuration-snippet : |
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
- {{ .Values.ingress.host }}
- host : {{ .Values.ingress.host }}
apiVersion : networking.k8s.io/v1
traefik.ingress.kubernetes.io/router.entrypoints : websecure
traefik.ingress.kubernetes.io/router.tls : " true "
traefik.ingress.kubernetes.io/router.tls.certresolver : letsencrypt
traefik.ingress.kubernetes.io/router.middlewares : leaflock-security@kubernetescrd
- host : {{ .Values.ingress.host }}
📈 Auto-Scaling Setup
HPA Configuration:
CPU-based scaling for backend
Memory-based scaling for frontend
Custom metrics scaling (optional)
Min/max replica constraints
apiVersion : autoscaling/v2
kind : HorizontalPodAutoscaler
minReplicas : {{ .Values.backend.autoscaling.minReplicas }}
maxReplicas : {{ .Values.backend.autoscaling.maxReplicas }}
averageUtilization : {{ .Values.backend.autoscaling.targetCPUUtilizationPercentage }}
averageUtilization : {{ .Values.backend.autoscaling.targetMemoryUtilizationPercentage }}
stabilizationWindowSeconds : 300
stabilizationWindowSeconds : 0
apiVersion : autoscaling.k8s.io/v1
kind : VerticalPodAutoscaler
# Default configuration values
repository : leaflock/frontend
corsOrigins : " https://leaflock.yourdomain.com "
targetCPUUtilizationPercentage : 70
repository : leaflock/backend
jwtSecret : "" # Required: base64 encoded 64-char secret
encryptionKey : "" # Required: base64 encoded 32-char key
targetCPUUtilizationPercentage : 70
targetMemoryUtilizationPercentage : 80
password : "" # Required: secure password
password : "" # Required: secure password
host : leaflock.yourdomain.com
email : admin@leaflock.app
password : "" # Required: secure admin password
schedule : " 0 2 * * * " # Daily at 2 AM
corsOrigins : " https://leaflock.yourdomain.com,https://www.leaflock.yourdomain.com "
storageClass : " premium-ssd "
storageClass : " premium-ssd "
bucket : " leaflock-backups-prod "
📦 Helm Deployment Process
Step-by-step deployment:
Generate secure secrets
Configure values file
Install Helm chart
Verify deployment
Test application
kubectl create namespace leaflock
kubectl create secret generic leaflock-secrets \
--from-literal=postgres-password=$(openssl rand -base64 32 ) \
--from-literal=redis-password=$(openssl rand -base64 32 ) \
--from-literal=jwt-secret=$(openssl rand -base64 64 ) \
--from-literal=encryption-key=$(openssl rand -base64 32 ) \
--from-literal=admin-password=$(openssl rand -base64 32 ) \
helm install leaflock ./helm \
--values helm/values-prod.yaml \
--set ingress.host=leaflock.yourdomain.com \
--set frontend.corsOrigins= " https://leaflock.yourdomain.com "
helm upgrade leaflock ./helm \
--values helm/values-prod.yaml
# 5. Check deployment status
kubectl get pods -n leaflock
kubectl get services -n leaflock
kubectl get ingress -n leaflock
# Deploy individual components
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/secrets.yaml
kubectl apply -f k8s/database/
kubectl apply -f k8s/redis/
kubectl apply -f k8s/backend/
kubectl apply -f k8s/frontend/
kubectl apply -f k8s/ingress.yaml
kubectl get all -n leaflock
📊 Monitoring Stack
Observability Components:
Prometheus for metrics collection
Grafana for visualization
AlertManager for notifications
Jaeger for distributed tracing
FluentD for log aggregation
image : prom/prometheus:latest
mountPath : /etc/prometheus
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --web.console.libraries=/etc/prometheus/console_libraries
- --web.console.templates=/etc/prometheus/consoles
claimName : prometheus-pvc
image : grafana/grafana:latest
- name : GF_SECURITY_ADMIN_PASSWORD
mountPath : /var/lib/grafana
# ServiceMonitor for Prometheus
apiVersion : monitoring.coreos.com/v1
💾 Backup Strategy
Backup Components:
Database backups with pg_dump
Persistent volume snapshots
Configuration backups
S3/Object storage integration
Automated restoration testing
schedule : " 0 2 * * * " # Daily at 2 AM
image : postgres:15-alpine
export PGPASSWORD=$POSTGRES_PASSWORD
pg_dump -h postgres -U postgres notes > /backup/backup-$(date +%Y%m%d_%H%M%S).sql
aws s3 cp /backup/backup-$(date +%Y%m%d_%H%M%S).sql s3://your-backup-bucket/
find /backup -name "backup-*.sql" -mtime +7 -delete
- name : POSTGRES_PASSWORD
- name : AWS_ACCESS_KEY_ID
- name : AWS_SECRET_ACCESS_KEY
# Disaster recovery procedure
# 1. Restore database from backup
kubectl exec -it postgres-0 -n leaflock -- psql -U postgres -c " DROP DATABASE IF EXISTS notes; "
kubectl exec -it postgres-0 -n leaflock -- psql -U postgres -c " CREATE DATABASE notes; "
kubectl exec -i postgres-0 -n leaflock -- psql -U postgres notes < backup.sql
# 2. Restart backend services
kubectl rollout restart deployment/backend -n leaflock
# 3. Verify application health
kubectl get pods -n leaflock
curl https://leaflock.yourdomain.com/api/v1/health
🔒 Network Security
Security Measures:
Network policies for traffic isolation
Pod security policies
Secret encryption at rest
RBAC for service accounts
Security scanning and compliance
apiVersion : networking.k8s.io/v1
name : leaflock-network-policy
apiVersion : policy/v1beta1
allowPrivilegeEscalation : false
requiredDropCapabilities :
- ' persistentVolumeClaim '
🔌 Pod Connectivity
Issue: Pods can’t communicate
Debug Commands:
kubectl get pods -n leaflock -o wide
kubectl exec -it backend-xxx -n leaflock -- wget -qO- http://postgres:5432
kubectl get svc -n leaflock
📊 Resource Issues
Issue: OOM kills or CPU throttling
Debug Commands:
kubectl top pods -n leaflock
# Describe problematic pod
kubectl describe pod backend-xxx -n leaflock
kubectl get hpa -n leaflock
kubectl logs -f deployment/backend -n leaflock
kubectl logs -f deployment/frontend -n leaflock
kubectl exec -it backend-xxx -n leaflock -- nslookup postgres
kubectl exec -it backend-xxx -n leaflock -- ping redis
kubectl describe ingress leaflock-ingress -n leaflock
Kubernetes Production Ready
This Kubernetes deployment guide provides enterprise-grade configuration with high availability, auto-scaling, monitoring, and security best practices.