Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How to use cloudsql proxy in a kubernetes cron job? #143
I have a cron job that requires database access, and I noticed that as long as the cloudsql connection stays open, the pod never gets removed from the list of pods, it stays in the "completed" state (it has 1/2 in the READY column), and they keep piling up.
Is there a way to close the cloudsql connection eg. after 1 connection have been made, so that the pods could clear up?
I don't think closing the Proxy client process after a single connection is a good idea in general - transient issues are bound to cause problems with a single TCP connection in the long run and your application should be configured to retry (and the driver will redial) as needed. If the Proxy exited after a single connection this retry strategy would not work.
While this may be OK in your specific use case (for example, if the cron can just fail because it will be retried in X minutes anyway), we need to avoid adding knobs for every usecase that someone needs. I believe that @pdecat's link to the kubernetes issue is a better long-term solution: it'd be nice if every sidecar container didn't have to implement some workaround. In fact, earlier today someone posted a workaround for this use case: kubernetes/kubernetes#25908 (comment) . I haven't tried it so YMMV, but looking at the code this is the sort of workaround I was about to suggest you trying.