apiVersion: apps/v1
kind: Deployment
metadata:
  name: vaultwarden
  labels:
    app: vaultwarden
spec:
  replicas: 1
  selector:
    matchLabels:
      app: vaultwarden
  template:
    metadata:
      labels:
        app: vaultwarden
    spec:
      containers:
        - name: vaultwarden
          image: vaultwarden/server:1.32.7-alpine
          resources:
            requests:
              memory: "128Mi"
              cpu: "100m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          ports:
            - containerPort: 80
          env:
            - name: WEBSOCKET_ENABLED
              value: "true"
            - name: DOMAIN
              value: "https://vaultwarden.lotimmy.com"
            - name: ADMIN_TOKEN
              valueFrom:
                secretKeyRef:
                  name: vaultwarden-secret
                  key: ADMIN_TOKEN
          # Health check
          livenessProbe:
            httpGet:
              path: /alive
              port: 80
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /alive
              port: 80
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          volumeMounts:
            - mountPath: "/data"
              name: data-vol
        - name: nginx-well-known
          image: nginx:alpine
          resources:
            requests:
              memory: "32Mi"
              cpu: "50m"
            limits:
              memory: "64Mi"
              cpu: "100m"
          ports:
            - containerPort: 8080
          volumeMounts:
            - mountPath: "/etc/nginx/conf.d"
              name: nginx-config
          livenessProbe:
            httpGet:
              path: /alive
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /alive
              port: 8080
            initialDelaySeconds: 3
            periodSeconds: 10
      volumes:
        - name: data-vol
          persistentVolumeClaim:
            claimName: vaultwarden-pvc
        - name: nginx-config
          configMap:
            name: nginx-well-known-config
