https://pulumi.com logo
Title
s

some-continent-7311

01/19/2022, 11:07 AM
Hello everyone. We run our software in GKE and use PostgreSQL Cloud SQL as database backend. We want to use PgBouncer as connection pool middleware, implemented as a microservice in GKE. Is there any good Pulumi tutorial on how to achieve that? Thank you.
p

prehistoric-activity-61023

01/19/2022, 11:27 AM
What are you struggling with?
Do you need some help with managing GKE and CloudSQL from pulumi or you’re asking how you can deploy PgBouncer within k8s cluster?
s

some-continent-7311

01/19/2022, 11:52 AM
Well, the setup I see is this: • Create a Docker image with PgBouncer in it • Deploy it to GKE using Pulumi • Change the connection strings to point to PgBouncer instead of Cloud SQL
What is not clear to me is how to specify the correct connection string from PgBouncer to Cloud SQL. The official documentation recommends to connect to Cloud SQL using Cloud SQL Auth proxy and load it as sidecar in the same pod as, I assume, PgBouncer.
Does it mean that the connection will look like this: microservice -> PgBouncer -> Cloud SQL Auth proxy -> Cloud SQL?
In terms of hosts and ports, is it going to be something like: microservice: pgbouncer-service:6432 (example port) -> localhost:5432 -> <cloud-sql-connection-stringg>:5432 -> Cloud SQL?
… or is there a simpler way to deploy PgBouncer to GKE?
p

prehistoric-activity-61023

01/19/2022, 11:59 AM
Did you enable private connection in Cloud SQL?
It’s possible to setup CloudSQL and GKE to communicate over private IP address. In that case, you can simply get rid of cloud sql proxy.
but the way you described it seems legit as well. That’s how I did it back in time when private connections were not available in GCP (although without PgBouncer)
s

some-continent-7311

01/19/2022, 12:22 PM
If private connection is enabled, what should I specify as host in PgBouncer config file in the
[databases]
section?
p

prehistoric-activity-61023

01/19/2022, 12:39 PM
IP address of the Cloud SQL instance
s

some-continent-7311

01/19/2022, 12:40 PM
Great, thank you!
p

prehistoric-activity-61023

01/19/2022, 12:41 PM
you can get this value from
private_ip_address
output 🙂
1