Deploy PostgreSQL on GKE using Helm and using Robin storage

Suds Kumar
4 min readMay 27, 2023

In this Part-II post, we will deploy a PostgreSQL database on Google Kubernetes Engine (GKE) using Helm and load data in the database. Before reading through this, do visit Part-I post where we installed Robin Storage on GKE as a prerequisite for this post.

Let’s create a PostgreSQL database using Helm and Robin Storage. We will be using Bitnami packaged PostgreSQL distribution. To do so, firstly add the Bitnami repository to Helm with the following command run in cloud shell:

helm repo add bitnami https://charts.bitnami.com/bitnami

Let’s now install PostgreSQL database by running the below command in cloud shell. We are setting the storageClass to “robin” to benefit from data management capabilities Robin Storage brings.

helm install pgtestdb --set global.storageClass=robin bitnami/postgresql

Run the command “helm list” to verify the installation.

Next we will connect to the PostgreSQL instance. Exit out of the robin container bash environment on to main cloud shell environment. Run the below commands to set the POSTGRES_PASSWORD environment variable and port forward PostgreSQL service port to host.

export POSTGRES_PASSWORD=$(kubectl get secret — namespace default pgtestdb-postgresql -o jsonpath=”{.data.postgres-password}” | base64 -d)

kubectl port-forward — namespace default svc/pgtestdb-postgresql 5432:5432 &

PGPASSWORD=”$POSTGRES_PASSWORD” psql — host 127.0.0.1 -U postgres -d postgres -p 5432

We will be connected to PostgreSQL instance now. We will use sample movie data to load data into our PostgreSQL database. For this let’s create a new database “movies”.

Next we will create a table and insert few rows.

To see the movies added to the “moviestab” table, run the following command with a filter for genre = ‘Drama’.

We have now deployed a PostgreSQL database on GKE with a table and some sample data.

To benefit from data management capabilities Robin brings, such as taking snapshots, making clones, and creating backups, we have to register this PostgreSQL Helm release as an application with Robin. The command to do so is - “robin app register”, but in our installation scenario this is bit different.

The PostgreSQL release installation we did under default namespace, which the Robin user admin doesn’t have access. Also ‘default’ namespace is not by default added to Robin’s namespace, so we have to import it. The import automatically enables the discovery/ registering of the applications under default and an explicit “app register” is not required. Nevertheless in a production like environment, the default namespace and admin user should not be used as pattern. A separate Robin user for applications as well as named namespaces should be used.

Just to show that the app is automatically discovered and registered, we will next run the command “robin app register”, which will error out saying the “Application pgtestdb already exists”.

Let’s verify Robin is now tracking the PostgreSQL Helm release as a single entity (app). We can do so using “robin app list” and “robin app info” commands as below.

We have now deployed the PostgreSQL database, loaded data, and registered the PostgreSQL Helm release with Robin. This concludes Part-II of Robin CNS series of posts. In Part-III we will test some of the advanced data management features of Robin storage such as Snapshot and Backup.

--

--