apiVersion: apps/v1 # for versions after 1.9.0 use apps/v1
kind: Deployment
metadata:
  name: wilipay-admin-deployment
spec:
  selector:
    matchLabels:
      app: wilipay-admin
  replicas: 3
  template:
    metadata:
      labels:
        app: wilipay-admin
    spec:
      containers:
      - name: php-fpm-nginx-admin
        image: eu.gcr.io/beetfree-193913/wilipay-admin
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 80
        volumeMounts:
          - name: cloudstorage-credentials
            mountPath: /root/credentials
            readOnly: true
          - name: ssl-key
            mountPath: /root/ssl/key
            readOnly: true
          - name: ssl-crt
            mountPath: /root/ssl/crt
            readOnly: true

        env:
          # These secrets are required to start the pod.
          # [START cloudsql_DB_secrets]
          - name: DB_USERNAME
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: username
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: password

      - name: cloudsql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.11
        command: ["/cloud_sql_proxy",
                  "-instances=beetfree-193913:europe-west1:wilipay-cloud-sql=tcp:5432",
                  "-credential_file=/secrets/cloudsql/wilipay-cloud-sql.json"]
        volumeMounts:
          - name: cloudsql-instance-credentials
            mountPath: /secrets/cloudsql
            readOnly: true
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
        - name: cloudstorage-credentials
          secret:
            secretName: cloudstorage-credentials
        - name: ssl-crt
          secret:
            secretName: ssl-crt
        - name: ssl-key
          secret:
            secretName: ssl-key
      # [END volumes]
