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?
Hi, there's a kubernetes issue tracking the more general use case of sidecar containers for batch workloads: https://github.com/kubernetes/kubernetes/issues/25908
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: https://github.com/kubernetes/kubernetes/issues/25908#issuecomment-365924958 . 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.
It appears the question was resolved. Closing issue.
Most helpful comment
Hi, there's a kubernetes issue tracking the more general use case of sidecar containers for batch workloads: https://github.com/kubernetes/kubernetes/issues/25908