<p>I am trying to deploy Postgres on Bluemix Container service (Kubernetes)</p>

<p>I have created the Image and deployed it through the following yaml file:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: tripbru-postgres
  labels:
    app: tripbruREST
spec:
  ports:
    - port: 5432
      targetPort: 5432
      nodePort: 31432
  selector:
    app: tripbruREST
    tier: frontend
  type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: tripbru-postgres
  labels:
    app: tripbruREST
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: tripbruREST
        tier: postgres
    spec:
      containers:
      - image: registry.ng.bluemix.net/eliza/postgres:9.5
        name: postgres
        env:
        - name: POSTGRES_PASSWORD
          value: MYPASSWORD
        ports:
        - containerPort: 5432
          name: postgres
        volumeMounts:
        - name: pg-data
          mountPath: /var/lib/postgresql/data
        - name: tz-config
          mountPath: /etc/localtime
      volumes:
      - name: pg-data
        emptyDir: {}
      - name: tz-config
        hostPath:
          path: /usr/share/zoneinfo/Europe/Madrid
</code></pre>

<p>This effectively deploys it:</p>

<pre><code>icordoba$ kubectl get services
NAME               CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes         10.10.10.1     &lt;none&gt;        443/TCP          1d
tripbru-postgres   10.10.10.232   &lt;nodes&gt;       5432:31432/TCP   1d
</code></pre>

<p>But I can't connect to the node IP address on port 31432. I have tested Postgres is running using:</p>

<pre><code>kubectl exec -it tripbru-postgres-3667814974-pzmsk bash
</code></pre>

<p>I get in the docker instance and check Postgres is running ok.</p>

<p>I am sure I am missing something. Do I need any other yaml file? Thanks.</p>

<p>I solved it using "Pod" and not Deployment. I also changed hostPath and note the ephemeral "emptyDir" volume format (this is a test in free Kubernetes service by Bluemix so I can't use real volumes). This is the working yaml:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: postgres
  labels:
    name: postgres
spec:
  containers:
    - name: postgres
      image: registry.ng.bluemix.net/eliza/postgres:9.5
      env:
        - name: POSTGRES_PASSWORD
          value: MYPASSWORD
      ports:
        - containerPort: 5432
      volumeMounts:
        - name: pg-data
          mountPath: /var/lib/postgresql/data
        - name: tz-config
          mountPath: /etc/localtime
  volumes:
  - name: pg-data
    #emptyDir: {}
    hostPath:
      path: "/opt/tripbruPostgres"
  - name: tz-config
    hostPath:
      path: /usr/share/zoneinfo/Europe/Madrid
</code></pre>

<p>(Note I still don't know what was wrong with my "Deployment" approach, but using Pod works as I don't need replication at this stage)</p>
