Exposing postgres service

286 views
Skip to first unread message

Nigel Jones

unread,
Mar 11, 2022, 10:43:28 AM3/11/22
to Postgres Operator
I have a simple cluster working nicely, as per tutorial.

One question — When I look at the services I see:

NAME                  TYPE           CLUSTER-IP       EXTERNAL-IP                         PORT(S)          AGE
employees-ha          ClusterIP      111.222.111.222    <none>                              5432/TCP         12m
employees-ha-config   ClusterIP      None             <none>                              <none>           12m
employees-pods        ClusterIP      None             <none>                              <none>           12m
employees-primary     ClusterIP      None             <none>                              5432/TCP         12m
employees-replicas    ClusterIP      111.222.111.222   <none>                              5432/TCP         12m

(Ip addresses modified)

And pods:

NAME                             READY   STATUS      RESTARTS   AGE
employees-backup-l4sj--1-c9xzm   0/1     Completed   0          30m
employees-instance1-7jsq-0       3/3     Running     0          31m
employees-instance1-942s-0       3/3     Running     0          31m
employees-instance1-m842-0       3/3     Running     0          31m
employees-repo-host-0            1/1     Running     0          31m


I was slightly unsure which pods or service to expose, and tried

✗   kubectl expose service/employees-primary --type=LoadBalancer --port=5432 --target-port=5432 --name employees
error: couldn't retrieve selectors via --selector flag or introspection: the service has no pod selector set
See 'kubectl expose -h' for help and examples

So at this point I probably need to check the pod annotations and figure out how to define my service, but I would have expected this to have been done in one of these services already.

I’m running OpenShift on IBMCloud.

Any tips?

Thanks
Nigel Jones


David Jeffers

unread,
Mar 12, 2022, 5:38:50 PM3/12/22
to Postgres Operator, Nigel Jones
Likely you're looking to expose the primary service. Have you tried modifying the service type? The documentation outlines this process here:
You should be able to use NodePort or LoadBalancer there. If you wanted to make your own service manually, just use the labels you find on the "employees-primary" service.

Kenji Shum

unread,
Sep 2, 2022, 4:52:14 AM9/2/22
to Postgres Operator, David Jeffers, Nigel Jones
Hi David,

I'm trying to migrate our current postgres DB to use PGO, but we have many applications from many teams that are using a specific DNS name to connect to the database inside of our k8s cluster. Therefore, I'm trying to create a service manually so that I can set the service name to be the same as the old DB.

I came across this thread but using the labels to create a service seems to not be working - I am unable to connect to the psql.

Do you know if the method of creating a service using the same labels still works in the current version?

Thanks,
Kenji 

David Jeffers

unread,
Sep 7, 2022, 5:42:16 PM9/7/22
to Postgres Operator, Kenji Shum, David Jeffers, Nigel Jones
Hey Kenji,

What labels are you using? How does psql respond to the connection attempt? Do your TLS certificates accommodate the new name you're using?
Reply all
Reply to author
Forward
0 new messages