Service defined without a selector?

2,621 views
Skip to first unread message

Lars Kellogg-Stedman

unread,
Nov 9, 2021, 4:24:57 PM11/9/21
to Postgres Operator
I've created a postgres cluster using PGO v5.0.3. I wanted to port-forward the service to my local machine to interact directly with the database, but the command failed:

$ oc port-forward service/netbox-primary 5432:5432
error: cannot attach to *v1.Service: invalid service 'netbox-primary': Service is defined without a selector

And indeed, the service has no "selector":

$ oc get service netbox-primary -o yaml
apiVersion: v1
kind: Service
metadata:
  labels:
  name: netbox-primary
  namespace: netbox
spec:
  clusterIP: None
  clusterIPs:
  - None
  ipFamilies:
  - IPv4
  - IPv6
  ipFamilyPolicy: RequireDualStack
  ports:
  - name: postgres
    port: 5432
    targetPort: postgres

Is that expected? The corresponding -replicas and -pods services have selectors. The -ha service does not.

Jonathan S. Katz

unread,
Nov 9, 2021, 4:43:49 PM11/9/21
to Lars Kellogg-Stedman, Postgres Operator
Yes, this is a property of setting up headless Services for Statefulsets.[1][2]

The PGO quickstart describes how to connect via a port-forward locally with a one-ish liner:


Thanks,

Jonathan

Nigel Jones

unread,
Mar 12, 2022, 8:23:20 AM3/12/22
to Postgres Operator, Jonathan S. Katz, Postgres Operator, Lars Kellogg-Stedman
Thanks,
In the end I created  LoadBalancer service and added this crucial element to the service selector:

as it seems this is what the operator manages to label the current master pod

(A bit new to postgres deployment & this operator -- this is only for dev use in any case)

Reply all
Reply to author
Forward
0 new messages