apiVersion: apps/v1
kind: Deployment
metadata:
  name: webserver
  labels:
    app.kubernetes.io/name: takahe
    app.kubernetes.io/component: webserver
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: takahe
      app.kubernetes.io/component: webserver
  replicas: 1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: takahe
        app.kubernetes.io/component: webserver
    spec:
      initContainers:
        - name: migrations
          image: jointakahe/takahe:0.8.0
          args: 
            - python3
            - manage.py
            - migrate
          env:
            - name: PGPASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgresql-creds
                  key: USER_PASSWORD
          envFrom:
            - configMapRef:
                name: takahe-config
            - secretRef:
                name: takahe-secrets
      containers:
        - name: webserver
          image: jointakahe/takahe:0.8.0
          args:
            - gunicorn
            - takahe.wsgi:application
            - -w
            - "6"
            - -b
            - "0.0.0.0:8000"
          ports:
            - containerPort: 8000
          env:
            - name: PGPASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgresql-creds
                  key: USER_PASSWORD
          envFrom:
            - configMapRef:
                name: takahe-config
            - secretRef:
                name: takahe-secrets
          volumeMounts:
            - name: cache
              mountPath: /cache
            - name: media
              mountPath: /media
          resources:
            limits:
              memory: "1024Mi"
              cpu: 1
          livenessProbe:
            httpGet:
              path: /
              port: 8000
            periodSeconds: 5
          readinessProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 5
            periodSeconds: 5
          startupProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 2
            failureThreshold: 30
            periodSeconds: 2
      volumes:
        - name: cache
          emptyDir: {}
        - name: media
          persistentVolumeClaim:
            claimName: takahe-media