With every StackGres cluster that you deploy a few services will be deployed. To connect to the database you only need to be aware of two services: the primary and the replica service.
The primary service is used to connect to the primary node and the replica service is used to access any of the replica nodes.
These services will follow a convention that is based in the cluster name and the function of the service, so that, the name of the services will be:
${CLUSTER-NAME}-primary${CLUSTER-NAME}-replicasBoth services will accept connections to ports 5432 and 5433 where:
5432 will point to pgbouncer - used by the application5433 will point to postgres - used for replication purposesTherefore, given a cluster with name “stackgres” in the namespace “demo”, the primary node will accessible through
the URL: stackgres-primary.demo:5432. Meanwhile, the replica node is accessible through the URL: stackgres-replicas.demo:5432.
For all the following examples we’re going to assume that we have a StackGres cluster named stackgres in the namespace demo.
psqlWith a pod with psql running in the same kubernetes cluster than the StackGres cluster, we can connect to the primary node with the following command:
PGPASSWORD=1775-d517-4136-958 psql -h stackgres-primary.demo -U postgres