Using a pod without using the node ip

8/18/2015

I have a postgres pod running locally on a coreOS vm. I am able to access postgres using the ip of the minion it is on but I'm attempting to set it up in such a manner as to not have to know exactly which minion the pod is on but still be able to use postgres.

Here is my pod

apiVersion: v1
kind: Pod
metadata:
  name: postgresql
  labels:
    role: postgres-client
spec:
  containers:
  - image: postgres:latest
    name: postgres
    ports:
    - containerPort: 5432
      hostPort: 5432
      name: pg-port
    volumeMounts:
      - name: nfs
        mountPath: /mnt
  volumes:
    - name: nfs
      nfs:
       server: nfs.server
       path: /

and here is a service I tried to set-up but it doesn't seem correct

apiVersion: v1
kind: Service
metadata:
  name: postgres-client
spec:
  ports:
    - port: 5432
      targetPort: 5432
  selector:
    app: postgres-client
-- hiltyj
kubernetes

1 Answer

8/19/2015

I'm guessing that the selector for your service is not finding any matching backends.

Try changing

app: postgres-client

to

role: postgres-client

in the service definition (or vice versa in the pod definition above).

The label selector has to match both the key and value (i.e. role and postgres-client). See the Labels doc for more details.

-- CJ Cullen
Source: StackOverflow