Can I use 'ha' service instead of 'primary' service for a specific use case?

48 views
Skip to first unread message

Shahid Hussain

unread,
Mar 24, 2023, 10:50:40 AM3/24/23
to Postgres Operator

Hello everyone!.
This query is regarding relation between 'ha' and 'primary' service.

Following are my observations.
The endpoint for the 'primary' service is pointing to the Cluster IP of the 'ha' service, and the endpoint for the 'ha' service is pointing to the actual IP of the pod. This means that all communication to the 'primary' service is routed to the pod via the 'ha' service.

[root@master-nfs-sfe ~]# kubectl get svc -n sfe|grep pgdb
pgdb-ha                                       ClusterIP   10.233.60.57    <none>        5432/TCP                     2d
pgdb-ha-config                                ClusterIP   None            <none>        <none>                       2d
pgdb-pgbouncer                                ClusterIP   10.233.11.88    <none>        5432/TCP                     2d
pgdb-pods                                     ClusterIP   None            <none>        <none>                       2d
pgdb-primary                                  ClusterIP   None            <none>        5432/TCP                     2d
pgdb-replicas                                 ClusterIP   10.233.47.6     <none>        5432/TCP                     2d


[root@master-nfs-sfe ~]# kubectl describe svc -n sfe pgdb-primary
Name:              pgdb-primary
Namespace:         sfe
..
IP:                None
IPs:               None
Port:              postgres  5432/TCP
TargetPort:        postgres/TCP
Endpoints:         10.233.60.57:5432

[root@master-nfs-sfe ~]# kubectl describe svc -n sfe pgdb-ha
Name:              pgdb-ha
..
IP:                10.233.60.57
IPs:               10.233.60.57
Port:              postgres  5432/TCP
TargetPort:        postgres/TCP
Endpoints:         10.233.112.130:5432
Session Affinity:  None
Events:            <none>


Can applications be configured to use the 'ha' service directly instead of the 'primary' service?
Since primary service  is a headless service which doesn't have cluster IP assigned and direct communication from master node is not possible. in this case shall we rely on connecting to 'ha' service?

Thanks & Regards,
Shahid


drew.s...@crunchydata.com

unread,
Mar 28, 2023, 3:37:48 PM3/28/23
to Postgres Operator, Shahid Hussain
Hello Shahid,

First off, while the Primary service does not have an IP address, the service name acts as a DNS name, so you should be fine to connect to it. Secondly, even if you did decide to connect directly to the HA service instead of the Primary service, you would not want to use the IP address, as that can change. Again, you'd want to use the DNS name.

So, if both the DNS names for the Primary and HA services resolve to the HA ClusterIP, why should you connect your apps to the Primary service? Well, the short answer is probably "architectural consistency." The HA service exists because we currently use Kubernetes Endpoints for Patroni's DCS. It's possible that this might change in the future and the HA service could go away. The Primary service will exist regardless and will still be the appropriate connection point for your applications.

I hope this helps!

Regards,
Drew
Reply all
Reply to author
Forward
0 new messages