how to connect to k8s cluster with bitnami postgresql-ha deployed?

7/26/2021

My setup (running locally in two minikubes) is I have two k8s clusters:

1) frontend cluster is running a golang api-server, 2) backend cluster is running an ha bitnami postgres cluster (used bitnami postgresql-ha chart for this)

Although if i set the pgpool service to use nodeport and i get the ip + port for the node that the pgpool pod is running on i can hardwire this (host + port) to my database connector in the api-server (in the other cluster) this works. However what i haven't been able to figure out is how to generically connect to the other cluster (e.g. to pgpool) without using the ip address?

I also tried using Skupper, which also has an example of connecting to a backend cluster with postgres running on it, but their example doesn't use bitnami ha postgres helm chart, just a simple postgres install, so it is not at all the same.

Any ideas?

-- Jim Smith
kubernetes
postgresql

2 Answers

7/31/2021

After moving to the one cluster architecture, it became easier to see how to connect to the bitnami postgres-ha cluster, by trying a few different things finally this worked: -postgresql-ha-postgresql-headless:5432

(that's the host and port I'm using to call from my golang server)

Now i believe it should be fairly straightforward to also run the two cluster case using skupper to bind to the headless service.

-- Jim Smith
Source: StackOverflow

9/23/2021

For those times when you have to, or purposely want to, connect pods/deployments across multiple clusters, Nethopper (https://www.nethopper.io/) is a simple and secure solution. The postgresql-ha scenario above is covered under their free tier. There is a two cluster minikube 'how to' tutorial at https://www.nethopper.io/connect2clusters which is very similar to your frontend/backend use case. Nethopper is based on skupper.io, but the configuration is much easier and user friendly, and is centralized so it scales to many clusters if you need to.

To solve your specific use case, you would:

  1. First install your api server in the frontend and your bitnami postgresql-ha chart in the backend, as you normally would.
  2. Go to https://mynethopper.com/ and
    • Register
    • Clouds -> define both clusters (clouds), frontend and backend
    • Application Network -> create an application network
    • Application Network -> attach both clusters to the network
    • Application Network -> install nethopper-agent in each cluster with copy paste instructions.
    • Objects -> import and expose pgpool (call the service 'pgpool') in your backend.
    • Objects -> distribute the service 'pgpool' to frontend, using a distribution rule.

Now, you should see 'pgpool' service in the frontend cluster

kubectl get service

When the API server pods in the frontend request service from pgpool, they will connect to pgpool in the backend, magically. It's like the 'pgpool' pod is now running in the frontend.

The nethopper part should only take 5-10 minutes, and you do NOT need IP addresses, TLS certs, K8s ingresses or loadbalancers, a VPN, or an istio service mesh or sidecars.

-- cmunford
Source: StackOverflow