<p>I am using <a href="https://github.com/zalando/postgres-operator" rel="nofollow noreferrer">https://github.com/zalando/postgres-operator</a> and I have created a database cluster. The following services have been also created:</p>
<pre><code>databaker-users-db          ClusterIP   10.245.227.1     &lt;none&gt;        5432/TCP   52d
databaker-users-db-config   ClusterIP   None             &lt;none&gt;        &lt;none&gt;     52d
databaker-users-db-repl     ClusterIP   10.245.156.119   &lt;none&gt;        5432/TCP   52d
</code></pre>
<p>I would like to forward the service to localhost and I tried as follows:</p>
<pre><code>kubectl port-forward service/databaker-users-db 5432:5432
</code></pre>
<p>and it shows me:</p>
<pre><code>error: cannot attach to *v1.Service: invalid service 'databaker-users-db': Service is defined without a selector
</code></pre>
<p>The content of the yml file</p>
<pre><code>apiVersion: acid.zalan.do/v1
kind: postgresql
metadata:
  annotations:
    meta.helm.sh/release-name: users
    meta.helm.sh/release-namespace: dev
  labels:
    app.kubernetes.io/managed-by: Helm
    team: databaker
  name: databaker-users-db
  namespace: dev
spec:
  databases:
    databaker_users_db: databaker
  numberOfInstances: 2
  postgresql:
    version: '12'
  resources:
    limits:
      cpu: 500m
      memory: 500Mi
    requests:
      cpu: 100m
      memory: 100Mi
  teamId: databaker
  users:
    databaker:
      - superuser
      - createdb
  volume:
    size: 2Gi
</code></pre>
<p>What am I doing wrong?</p>

<p>It seems like, your k8s service <code>databaker-users-db</code> doesn't have <code>selector</code> specified.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: databaker-users-db
spec:
  ports:
  - ...
  - ...
  selector: &lt;-- check here
</code></pre>
<blockquote>
<p>When a Service has no selector, the corresponding Endpoint object is not created automatically. You can manually map the Service to the network address and port where it's running, by <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">adding an Endpoint object manually</a>.</p>
</blockquote>
