1

I am trying to deploy Postgres on Bluemix Container service (Kubernetes)

I have created the Image and deployed it through the following yaml file:

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

This effectively deploys it:

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

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

kubectl exec -it tripbru-postgres-3667814974-pzmsk bash

I get in the docker instance and check Postgres is running ok.

I am sure I am missing something. Do I need any other yaml file? Thanks.

Jeff Sloyer
  • 4,899
  • 1
  • 24
  • 48
icordoba
  • 1,834
  • 2
  • 33
  • 60
  • Can you add how you are trying to connect (from where, what tools you tested with)? – Norbert Jun 17 '17 at 17:08
  • Just to connect from Internet. I want to access that Postgres Pod using the external IP of the Node and port 31432. I have tried locally with Minikube and it works (same Yaml files). Thanks. – icordoba Jun 17 '17 at 17:15
  • Check it from the host (one of your nodes), because it looks like you might have to allow access to the port somewhere in a bluemix firewall config – Norbert Jun 17 '17 at 18:04

1 Answers1

1

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:

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

(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)

icordoba
  • 1,834
  • 2
  • 33
  • 60