I am trying to connect to cloud sql from k8s instance with a side-car proxy running at the same pod.
According to Google guidelines i should reuse Service Account with JSON private key to let pod to access given SQL instance.
With newly created SQL instance i seem automatically get Service Account which looks like:
[hash]@speckle-umbrella-pg-8.iam.gserviceaccount.com
With this account, how can i generate JSON private key? I was trying to create SSL certificate in "Connections" tab, but there is no option to create JSON ones.
As second option i was trying to reuse existing IAM service account - "Compute Engine default service account", having generated JSON key for it, but it did not work.
The way i set it up is:
- I create a secret
kubectl create secret generic cloudsql-instance-credentials --from-file=credentials.json=[PROXY_KEY_FILE_PATH] I attache container to the pod:
- name: cloudsql-proxy image: gcr.io/cloudsql-docker/gce-proxy:1.11 command: ["/cloud_sql_proxy", "-instances=project-name:us-central1:sql-instance-name=tcp:5432", "-credential_file=/secrets/cloudsql/credentials.json"] securityContext: runAsUser: 2 # non-root user allowPrivilegeEscalation: false volumeMounts: - name: cloudsql-instance-credentials mountPath: /secrets/cloudsql readOnly: true
Whts the correct way? Goole docs does not seem to contain complete information.