apiVersion: apps/v1
kind: Deployment
metadata:
  name: homepage
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 20%
      maxSurge: 10%
  selector:
    matchLabels:
      name: homepage
  template:
    metadata:
      labels:
        name: homepage
    spec:
      containers:
        - name: homepage
          image: asia.gcr.io/ianlewis-org/homepage
          # defines the health checking
          livenessProbe:
            # an http probe
            httpGet:
              path: /_status/healthz
              port: 8080
            # length of time to wait for a pod to initialize
            # after pod startup, before applying health checking
            initialDelaySeconds: 10
            timeoutSeconds: 5
          readinessProbe:
            # an http probe
            httpGet:
              path: /_status/readiness
              port: 8080
            # length of time to wait for a pod to initialize
            # after pod startup, before applying health checking
            initialDelaySeconds: 15
            timeoutSeconds: 5
          env:
            - name: DEBUG
              value: 'False'
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: homepage-secret
                  key: secret-key
            - name: DB_HOST
              value: mysql
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: homepage-db-secret
                  key: db-user
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: homepage-db-secret
                  key: db-password
            - name: MEDIA_ROOT
              value: /var/www/media
            - name: FILEBASED_CACHE_PATH
              value: /cache
            # - name: USE_MEMCACHED
            #   value: 'False'
            # - name: MEMCACHED_HOSTS
            #   value: memcached:11211
            - name: HTTPS
              value: "on"
          ports:
            - containerPort: 8080
          resources:
            requests:
              memory: 250Mi
              cpu: 200m
            limits:
              memory: 250Mi
              cpu: 1000m
          volumeMounts:
            - name: cache-dir
              mountPath: /cache
        - name: homepage-nginx
          image: asia.gcr.io/ianlewis-org/nginx:1.13.10-alpine
          ports:
            - containerPort: 8000
          volumeMounts:
            - name: nginx-conf
              mountPath: /etc/nginx
          resources:
            requests:
              memory: 10Mi
              cpu: 50m
            limits:
              memory: 10Mi
              cpu: 100m
      volumes:
        - name: nginx-conf
          configMap:
            name: homepage-nginx-conf
        - name: cache-dir
          emptyDir: {}
