Deploy PostgreSQL into IBM Cloud private

This story describes how to deploy PostgreSQL, an open source object-relational database system, into IBM Cloud private, IBM’s new Kubernetes based private cloud, by using helm charts and persistent volumes.

  1. The first step is to install IBM Cloud private . The detailed instructions to do so can be found here. Once you have installed IBM Cloud private, the next steps are as follows:
  • Create a persistent volume or set up dynamic provisioning
  • Install PostgreSQL 9.6.4 Helm Chart
  • Start using PostgreSQL!

Create a persistent volume

  1. Create a persistent volume and a persistent volume claim. This can be done using the IBM Cloud private App Centre UI as show below.
  2. On the upper left dropdown menu, click on Platform and select storage.

a) To create a persistent volume, click on Create persistent volume and then fill in the required details as shown below.

Enter the details on the following dialog box and click on create.

The persistent volume is now created.

b) Create a persitent volume claim as follows:

Click on the Persistent Volume claim tab and the click on Create PersistenVolumeClaim.

Enter the details in the following dialog box and click on create.

Note: It is required that the Access mode and size be the same for the persistent volume and the persistent volume claim.

The persistent volume claim is now created and bound to the persistent volume as seen below.

  1. Dynamic provisioning allows storage volumes to be created on-demand. You can use storage classes to provision these volumes. To setup dynamic provisioning environment, follow the instructions detailed here.With Dynamic Provisioning, no persistent volume or claim is required beforehand.
  2. Using the App Centre UI, you can setup dynamic provisioning during the installation of the chart by setting the “persistence.useDynamicProvisioning” field to true.

Install PostgreSQL 9.6.4 Helm chart

  1. The next step is to install PostgreSQL. There are two ways to install PostgreSQL:
  2. 1. Using IBM Cloud private’s UI to deploy the chart.
  3. Open IBM Cloud private 2.1 , log in and you will see the dashboard. From the upper left dropdown menu scroll to the bottom of the dropdown options and select, “Catalog”.

Select the ibm-postgres-dev chart and click on the chart.

Click on Configure to configure the chart

Enter the release name and select the checkbox to accept the license terms after reading them.

By default, the chart will create a user ‘postgres’ and generate a random password, but you can also specify your own values here:

Once you are ready and have reviewed the chart and all the advanced settings, click on Install.

Now your chart is deployed!

You can check the status of your deployment by clicking on Helm releases on the above dialog.

Clicking on your deployment will lead you to the page where you can check if your deployment is now in the running state.

2. From the command line by using Helm commands.

  1. For the second option to use the command line to deploy the chart, you can directly access the Helm charts at:
  2. The chart that deploys PostgreSQL creates the default user ‘postgres’ for you with a database called postgres.

Once installed, PostgreSQL can be used in the following manner:

  1. To get your deployment name, run

kubectl get pods

2. Use this deployment name for the next steps.

3. Get the user password using the following command:

PGPASSWORD=$(kubectl get secret --namespace default <deployment name> -o jsonpath="{.data.password}" | base64 --decode; echo)

4. To connect to your database, you can run the following command to start a simple client (using the environment variable from above):

kubectl run <deployment name>-client --rm --tty -i --image postgres \ --env "PGPASSWORD=$PGPASSWORD" \ --command -- psql -U postgres \

-h <deployment name> postgres

5. The following example shows the above commands in action:

6. To connect to your database directly from outside the K8s cluster:

a) If using the default setting for Nodeport:

PGHOST=$(kubectl get nodes --namespace default -o jsonpath='{.items[0].status.addresses[0].address}')
 PGPORT=$(kubectl get svc --namespace default <deployment name> -o jsonpath='{.spec.ports[0].nodePort}')

b) For cluster IP,

  1. PGHOST=
  2. PGPORT=5432
  3. Execute the following commands to route the connection:
     export POD_NAME=$(kubectl get pods --namespace default -l "app=<deployment name>" -o jsonpath="{.items[0]}")
     kubectl port-forward $POD_NAME 5432:5432


Using this story you can deploy and run PostgreSQL into IBM Cloud private.Thank you! Comments and questions are welcome.

Originally published at