I am starting up the cloudsql proxy as a sidecar to my app, and I notice that my app fails non-deterministically. After some trial and error, it appears that the proxy may take some time to start listening on its port(s). I believe that a Kubernetes healthcheck would solve this issue. Does the proxy support healthchecks?
Please check this for healthcheck using Kubernetes:
https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/119
Hi @AthenaShi - thanks for the reply and reference. Would you be open to a PR to add an HTTP endpoint that adds an endpoint that can be used as a health check?
Ya, sure!
We might incorporate this in the official sample manifest.
In the meanwhile can you give this livenessProbe with exec a try: https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/119#issuecomment-338749457 and see if it fixes your intermittent issues?
Thanks @ahmetb, the livenessProbe you linked to is helpful for ensuring the proxy is listening on a given port.
However, I wonder if a "healthy" state should also involve testing the connection to the instance. A few cases where the netcat test would succeed, but an application could not actually connect:
-instances argument pointing at a nonexistant instance nameI'm not sure whether those are appropriate to test continually while running the proxy, but I know we'd find use from testing it within a readinessProbe, to ensure any edits to the configuration don't break connectivity. (This is especially useful if running the proxy as a service, when you don't have application code and user credentials to test the connection.)
livenessProbe you linked to is helpful for ensuring the proxy is listening
you can probably ship the mysql CLI with the image (or write a small script alongside your container) that makes a simple ping query to the database and exits. You can still use "exec" livenessProbe for this purpose and it's a somewhat common practice to test liveness of non-HTTP systems via Kubernetes.
@arschles out of curiosity, when you proxy may take some time to start listening on its ports, how much time have you observed so far? I'm starting to do some troubleshooting on my own pods, and I still have yet to confirm it, but cloudsql proxy logging indicates that it could be hours after container start.
We were using https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/119#issuecomment-338749457 as our healthcheck but nc has been removed from the v1.16 release. What's the official recommendation now? Seems a bit crazy that we should have to create our own image to add livenessProbe support when using gce-proxy as a sidecar is a well-documented use-case.
Update for anyone that's relying on a shell, we do have alpine and buster images with shells still included.
Some additional thoughts on a path to execution for this:
The original issue mentions k8s probe, of which there are 3 different flavors:
This is probably relevant because it'll change how we want to judge "health". Are we "healthy" if the proxy is successfully receiving/acting on connections, or just if it's successfully reaching the database? What about for multiple instances?
Then it looks like there are 3 ways you can implement each probes:
TCP probably isn't helpful since it only validates that the proxy is listening to connections, but we could potentially implement one (or both) of the other two:
Most helpful comment
We were using https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/119#issuecomment-338749457 as our healthcheck but
nchas been removed from the v1.16 release. What's the official recommendation now? Seems a bit crazy that we should have to create our own image to add livenessProbe support when using gce-proxy as a sidecar is a well-documented use-case.