Setting up a connection pool for PostgreSQL does not have to be a complicated process. Actually, it can be a reasonably simple procedure if you know enough. In this repo you'll find a simple tutorial on how to deploy PgBouncer alongside a Postgres database in a kubernetes environment.
Note: This tutorial uses kustomize to configure and setup the deployment manifest. If you never used it before, it is a simple and powerful tool to customize kubernetes deployments.
- kubernetes cluster (e.g., miniconda, k3s/k3d, kind)
- kubectl (1.16+ kustomize)
- Linux / MacOS
- Start the kubernetes cluster
minikube start- Generate k8s deploy manifest
kubectl kustomize > deploy.yaml- Create the k8s resources
kubectl create -f deploy.yaml- Test the setup
kubectl -n database exec -it pg-0 -- bash -c 'PGPASSWORD=password_user1 psql -U user1 -h pgbouncer -p 5439 -d sandbox -c " SELECT * from test"'- Destroy the k8s resources
kubectl delete -f deploy.yaml- Clean remaining artifacts
rm deploy.yaml- https://www.pgbouncer.org/config.html
- https://gitlab.com/aztek-io/oss/containers/pgbouncer-container
- https://www.cybertec-postgresql.com/en/pgbouncer-authentication-made-easy/
- https://www.depesz.com/2012/12/02/what-is-the-point-of-bouncing/
- https://www.enterprisedb.com/postgres-tutorials/challenges-setting-maxconnections-and-why-you-should-use-connection-pooler