Kubernetes Installation
Deploy DBCraft on Kubernetes with a hardened, non-root manifest, secrets kept out of git, and persistent storage.
Prerequisites
- Kubernetes cluster (EKS, GKE, AKS, or self-managed)
kubectlconfigured with cluster access- StorageClass configured for PersistentVolumeClaims
- Ingress controller (nginx, traefik) for external access
Installation Steps
Create Namespace
Create a dedicated namespace for DBCraft:
apiVersion: v1
kind: Namespace
metadata:
name: dbcraft
labels:
app.kubernetes.io/name: dbcraftkubectl apply -f namespace.yamlCreate Secrets
Create the JWT secret and encryption key imperatively, so the values never land in a tracked file:
kubectl -n dbcraft create secret generic dbcraft-secrets \
--from-literal=JWT_SECRET="$(openssl rand -base64 48)" \
--from-literal=ENCRYPTION_KEY="$(openssl rand -base64 48)"Or, preferably, sync them from a secret manager with External Secrets Operator:
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: dbcraft-secrets
namespace: dbcraft
spec:
secretStoreRef:
name: aws-secretsmanager
kind: ClusterSecretStore
target:
name: dbcraft-secrets
data:
- secretKey: JWT_SECRET
remoteRef:
key: dbcraft/prod
property: jwt_secret
- secretKey: ENCRYPTION_KEY
remoteRef:
key: dbcraft/prod
property: encryption_keyENCRYPTION_KEY. Never apply a placeholder Secret over the real one: replacing or losing the key makes every stored credential undecryptable. Never commit secret values to version control.Create Persistent Volume
Create a PersistentVolumeClaim for data storage:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dbcraft-data
namespace: dbcraft
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp3 # Adjust for your cloud provider
resources:
requests:
storage: 10GiAdjust storageClassName for your cloud provider: AWS (gp3), GCP (standard), Azure (default).
kubectl apply -f pvc.yamlCreate Deployment
Deploy DBCraft as a non-root, read-only-root-filesystem container with health checks and resource limits:
apiVersion: apps/v1
kind: Deployment
metadata:
name: dbcraft
namespace: dbcraft
labels:
app.kubernetes.io/name: dbcraft
spec:
replicas: 1 # SQLite metadata store: run exactly one replica
strategy:
type: Recreate # never two pods on the same volume
selector:
matchLabels:
app.kubernetes.io/name: dbcraft
template:
metadata:
labels:
app.kubernetes.io/name: dbcraft
spec:
securityContext:
fsGroup: 1000
runAsUser: 1000
runAsGroup: 1000
initContainers:
- name: fix-permissions
image: busybox:1.36
command: ["sh", "-c", "chown -R 1000:1000 /app/data && chmod -R 755 /app/data"]
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
add: ["CHOWN", "FOWNER"]
seccompProfile:
type: RuntimeDefault
volumeMounts:
- name: data
mountPath: /app/data
containers:
- name: dbcraft
image: krishcdbry/dbcraft:v0.8.1-mcp
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 9000
protocol: TCP
env:
- name: RUST_LOG
value: "info"
- name: DBCRAFT__DATABASE__PATH
value: "/app/data/dbcraft.db"
- name: DBCRAFT__SERVER__BASE_URL
value: "https://dbcraft.yourdomain.com"
- name: DBCRAFT__AUTH__JWT_SECRET
valueFrom:
secretKeyRef:
name: dbcraft-secrets
key: JWT_SECRET
- name: DBCRAFT__SECURITY__ENCRYPTION_KEY
valueFrom:
secretKeyRef:
name: dbcraft-secrets
key: ENCRYPTION_KEY
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
volumeMounts:
- name: data
mountPath: /app/data
- name: tmp
mountPath: /tmp
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /api/v1/auth/setup-status
port: http
initialDelaySeconds: 10
periodSeconds: 30
timeoutSeconds: 10
readinessProbe:
httpGet:
path: /api/v1/auth/setup-status
port: http
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
volumes:
- name: data
persistentVolumeClaim:
claimName: dbcraft-data
- name: tmp
emptyDir: {}DBCRAFT__ prefix only. Setting bare JWT_SECRET or ENCRYPTION_KEY env vars does nothing, and the server falls back to generated keys. DBCRAFT__SERVER__BASE_URL must be the public https URL: OAuth and MCP discovery, links, and Secure cookies are built from it.replicas: 1 with the Recreate strategy; scaling out would put two writers on one database.kubectl apply -f deployment.yamlCreate Service
Expose DBCraft within the cluster:
apiVersion: v1
kind: Service
metadata:
name: dbcraft
namespace: dbcraft
labels:
app.kubernetes.io/name: dbcraft
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: dbcraftkubectl apply -f service.yamlCreate Ingress (Optional)
Expose DBCraft externally with TLS:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dbcraft
namespace: dbcraft
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: nginx
tls:
- hosts:
- dbcraft.yourdomain.com
secretName: dbcraft-tls
rules:
- host: dbcraft.yourdomain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: dbcraft
port:
number: 80kubectl apply -f ingress.yamlRestrict Ingress (Recommended)
Only let your ingress controller reach the pod, so nothing else in the cluster can call the API directly:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: dbcraft-default-deny-ingress
namespace: dbcraft
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: dbcraft
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
ports:
- protocol: TCP
port: 9000Change the namespace selector to wherever your ingress controller runs. For an AWS ALB in IP target mode, allow the VPC CIDR with an ipBlock instead.
kubectl apply -f networkpolicy.yamlVerify Installation
Check that all resources are running:
# Check pods
kubectl get pods -n dbcraft
# Check deployment
kubectl get deployment -n dbcraft
# View logs
kubectl logs -f deployment/dbcraft -n dbcraft
# Port forward for local testing, then check the version
kubectl port-forward svc/dbcraft 9000:80 -n dbcraft
curl -s http://localhost:9000/healthCloud-Specific Notes
AWS EKS
- • StorageClass:
gp3 - • Use the AWS Load Balancer Controller
- • Consider AWS Secrets Manager
GCP GKE
- • StorageClass:
standard - • Use GCP Ingress
- • Consider Secret Manager
Azure AKS
- • StorageClass:
default - • Use AGIC Ingress
- • Consider Key Vault
