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)
  • kubectl configured with cluster access
  • StorageClass configured for PersistentVolumeClaims
  • Ingress controller (nginx, traefik) for external access

Installation Steps

1

Create Namespace

Create a dedicated namespace for DBCraft:

namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: dbcraft
  labels:
    app.kubernetes.io/name: dbcraft
Terminal
kubectl apply -f namespace.yaml
2

Create Secrets

Create the JWT secret and encryption key imperatively, so the values never land in a tracked file:

Terminal
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:

external-secret.yaml
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_key
Back up the encryption key
Data source credentials are encrypted with ENCRYPTION_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.
3

Create Persistent Volume

Create a PersistentVolumeClaim for data storage:

pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dbcraft-data
  namespace: dbcraft
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: gp3  # Adjust for your cloud provider
  resources:
    requests:
      storage: 10Gi

Adjust storageClassName for your cloud provider: AWS (gp3), GCP (standard), Azure (default).

Terminal
kubectl apply -f pvc.yaml
4

Create Deployment

Deploy DBCraft as a non-root, read-only-root-filesystem container with health checks and resource limits:

deployment.yaml
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: {}
Configuration names
The server reads settings under the 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.
One replica only
DBCraft's metadata lives in SQLite on the volume. Keep replicas: 1 with the Recreate strategy; scaling out would put two writers on one database.
Terminal
kubectl apply -f deployment.yaml
5

Create Service

Expose DBCraft within the cluster:

service.yaml
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: dbcraft
Terminal
kubectl apply -f service.yaml
6

Create Ingress (Optional)

Expose DBCraft externally with TLS:

ingress.yaml
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: 80
DNS & TLS
Ensure your domain points to your Ingress controller's IP/load balancer. This example uses cert-manager for automatic TLS certificates.
Terminal
kubectl apply -f ingress.yaml
7

Restrict Ingress (Recommended)

Only let your ingress controller reach the pod, so nothing else in the cluster can call the API directly:

networkpolicy.yaml
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: 9000

Change 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.

Terminal
kubectl apply -f networkpolicy.yaml

Verify Installation

Check that all resources are running:

Terminal
# 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/health

Cloud-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

Next Steps