apiVersion: apps/v1
kind: Deployment
metadata:
  name: petclinic
spec:
  replicas: 2
  selector:
    matchLabels:
      app: petclinic
  template:
    metadata:
      labels:
        app: petclinic
    spec:
      containers:
      - name: petclinic
        image: "gcr.io/projetdevops-303216/petclinic:latest"
        ports:
          - containerPort: 8080
        # ... other container configuration
        env:
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: cloudsql-db-credential
              key: username
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              name: cloudsql-db-credential
              key: password
        - name: DB_NAME
          valueFrom:
            secretKeyRef:
              name: cloudsql-db-credential
              key: database
      - name: cloud-sql-proxy
        # It is recommended to use the latest version of the Cloud SQL proxy
        # Make sure to update on a regular schedule!
        image: gcr.io/cloudsql-docker/gce-proxy:1.17
        command:
          - "/cloud_sql_proxy"

          # If connecting from a VPC-native GKE cluster, you can use the
          # following flag to have the proxy connect over private IP
          # - "-ip_address_types=PRIVATE"

          # Replace DB_PORT with the port the proxy should listen on
          # Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
          - "-instances=projetdevops-303216:europe-west1:petclinicdv=tcp:3306"

        # [START cloud_sql_proxy_k8s_volume_mount]
          # This flag specifies where the service account key can be found
          - "-credential_file=/home/boukhatem_projects/secrets/service_account.json"
        securityContext:
          # The default Cloud SQL proxy image runs as the
          # "nonroot" user and group (uid: 65532) by default.
          runAsNonRoot: true
        volumeMounts:
        - name: my-secrets-volume
          mountPath: /home/boukhatem_projects/secrets
          readOnly: true
          # [END cloud_sql_proxy_k8s_volume_mount]
      # [START cloud_sql_proxy_k8s_volume_secret]
      volumes:
      - name: my-secrets-volume
        secret:
          secretName: cloudsql-instance-credentials
      # [START cloud_sql_proxy_k8s_volume_secret]
