apiVersion: apps/v1
kind: Deployment
metadata:
  name: golantg-test
  labels:
    app: golantg-test
spec:
  selector:
    matchLabels:
      app: golantg-test
  template:
    metadata:
      labels:
        app: golantg-test
    spec:
      containers:
        - name: web
          image: karnich/golang-mysql-test:v0.5
          ports:
            - containerPort: 80
          env:
            - name: golantg-test_DB_HOST
              value: 127.0.0.1:3306
            # These secrets are required to start the pod.
            # [START cloudsql_secrets]
            - name: golantg-test_DB_USER
              valueFrom:
                secretKeyRef:
                  name: mysql
                  key: username
            - name: golantg-test_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql
                  key: password
            # [END cloudsql_secrets]
        # Change <INSTANCE_CONNECTION_NAME> here to include your GCP
        # project, the region of your Cloud SQL instance and the name
        # of your Cloud SQL instance. The format is
        # $PROJECT:$REGION:$INSTANCE
        # [START proxy_container]
        - name: cloudsql-proxy
          image: gcr.io/cloudsql-docker/gce-proxy:1.11
          command: ["/cloud_sql_proxy",
                    "-instances=gke-project-1101:europe-west1:karnich-test=tcp:3306",
                    "-credential_file=/secrets/cloudsql/credentials.json"]
          # [START cloudsql_security_context]
          securityContext:
            runAsUser: 2  # non-root user
            allowPrivilegeEscalation: false
          # [END cloudsql_security_context]
          volumeMounts:
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
        # [END proxy_container]
      # [START volumes]
      volumes:
        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
      # [END volumes]