Issue connecting to Cloud SQL via Google Cloud Run when running locally via Cloud Code

91 Views Asked by At

I am attempting to run a Cloud Run container locally in VSCode via Cloud Code, but the trying to build it fails every time due to the following errors:

Waiting for deployments to stabilize...
 - ...: container cloud-sql-proxy terminated with exit code 1
    - ...: container cloud-sql-proxy terminated with exit code 1
      > Error retrieving logs for pod ...: exit status 1.
Try `kubectl logs d... -n default -c cloud-sql-proxy`

Running kubectl logs d... -n default -c cloud-sql-proxy gives me the following output:

E0228 10:35:09.202560    9698 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:53943/api?timeout=32s": dial tcp 127.0.0.1:53943: connect: connection refused
E0228 10:35:09.202732    9698 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:53943/api?timeout=32s": dial tcp 127.0.0.1:53943: connect: connection refused
E0228 10:35:09.203867    9698 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:53943/api?timeout=32s": dial tcp 127.0.0.1:53943: connect: connection refused
E0228 10:35:09.203994    9698 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:53943/api?timeout=32s": dial tcp 127.0.0.1:53943: connect: connection refused
The connection to the server 127.0.0.1:53943 was refused - did you specify the right host or port?

Any advice would be appreciated.

I am on a Mac M1 chip and my Cloud Run container is built with Dockerfile, in case that matters

1

There are 1 best solutions below

0
Jay Windsor On

I am an engineer on the Cloud Code team.

Local Cloud Run happens on a minikube profile named "cloud-run-dev-internal". We clean up after ourselves by deleting the deployment and pausing the minikube profile as soon as the session ends, and the session ends after your failure. Normally, the errors show up in the logs we output, but unfortunately this is not the case this time because it is in another container.

You can't get the logs because the cluster is stopped, and even if the cluster was not stopped you would find the deployment deleted.

Apologies for this being kinda hacky (we will look at providing better debug options in the future). Here's what I would recommend to see the logs for now:

  • Start your run/debug on Cloud Run emulator session.
  • As soon as you see the deployment status checking, CLOSE your VS Code window. This will prevent the detected failure deleting the deployment.
  • With the minikube profile still running this time, you can run your logs command in another terminal. For example: kubectl logs {{container name}} -c cloud-sql-proxy.