apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-mux
spec:
  replicas: 3
  selector:
    matchLabels:
      app: go-mux
  template:
    metadata:
      labels:
        app: go-mux
    spec:
      containers:
      - name: go-mux-api
        image: gcr.io/firewalkers/go-mux-api:_VER
        ports:
        - containerPort: 8010
        env:
          - name: APP_DB_USERNAME
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: username
          - name: APP_DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: password
          - name: APP_DBNAME
            valueFrom:
              secretKeyRef:
                name: cloudsql-db-credentials
                key: dbname

      - name: cloudsql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:latest
        command: ["/cloud_sql_proxy",
          "-instances=<INSTANCE_CONNECTION_NAME>=tcp:3306",
          "-credential_file=/secrets/cloudsql/sql_credentials.json"]
        volumeMounts:
          - name: my-secrets-volume
            mountPath: /secrets/cloudsql
            readOnly: true

      volumes:
        - name: my-secrets-volume
          secret:
            secretName: cloudsql-instance-credentials
