Skip to content

Exposing cluster

The Operator provides entry points for accessing the database by client applications. The database cluster is exposed with regular Kubernetes Service objects configured by the Operator.

This document describes the usage of Custom Resource manifest options to expose the clusters deployed with the Operator.


We recommend exposing the cluster through PgBouncer, which is enabled by default. You can disable pgBouncer by setting proxy.pgBouncer.replicas to 0.

The following example deploys two pgBouncer nodes exposed through a LoadBalancer Service object:

    replicas: 2
    image: percona/percona-postgresql-operator:2.3.1-ppg14-pgbouncer
      type: LoadBalancer

The Service will be called <clusterName>-pgbouncer:

$ kubectl get service
Expected output
NAME                 TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
cluster1-pgbouncer   LoadBalancer   5432:30601/TCP   20m

You can connect to the database using the External IP of the load balancer and port 5432.

If your application runs inside the Kubernetes cluster as well, you might want to use the Cluster IP Service type in proxy.pgBouncer.expose.type, which is the default. In this case to connect to the database use the internal domain name - cluster1-pgbouncer.<namespace>.svc.cluster.local.

Exposing the cluster without PgBouncer

You can connect to the cluster without a proxy. For that use <clusterName>-ha Service object:

$ kubectl get service
Expected output
NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
cluster1-ha          ClusterIP   <none>        5432/TCP   115s

This service points to the active primary. In case of failover to the replica node, will change the endpoint automatically.

To change the Service type, use expose.type in the Custom Resource manifest. For example, the following manifest will expose this service through a load balancer:

    type: LoadBalancer

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services. Join K8S Squad to benefit from early access to features and “ask me anything” sessions with the Experts.

Last update: 2024-02-19