Skip to content

farrajota/kubernetes-postgres-pgbouncer

Repository files navigation

Setting a connection pool using PgBouncer for PostgreSQL

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.

Requirements

  • kubernetes cluster (e.g., miniconda, k3s/k3d, kind)
  • kubectl (1.16+ kustomize)
  • Linux / MacOS

Setting up the environment / resources

  1. Start the kubernetes cluster
minikube start
  1. Generate k8s deploy manifest
kubectl kustomize > deploy.yaml
  1. Create the k8s resources
kubectl create -f deploy.yaml
  1. 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"'
  1. Destroy the k8s resources
kubectl delete -f deploy.yaml
  1. Clean remaining artifacts
rm deploy.yaml

References

License

MIT License

About

Tutorial on how to setup a connection pool using pgbouncer for PostgreSQL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published