How to deploy PostgreSQL using Kubernetes, Helm, and Trident

Overview

PostgreSQL is a popular open-source relational database, and in this post you will see how you can deploy PostgreSQL in a Kubernetes environment using Helm charts with Trident, a dynamic storage provisioner from NetApp for Kubernetes.

You will also learn how you can offer standard PostgreSQL deployments using templates (Helm) which do not require any storage pre-provisioning. Moreover, we will see how easy it is to scale and cleanup the PostgreSQL instances.

I have posted the related code on github and also created a demo video for your reference.

Understand

Which PostgreSQL container image did we use?

We used the PostgreSQL Docker image provided by CrunchyData for this deployment but you can use any PostgreSQL image of your choice.

Why do we need Helm?

Helm is a package manager for Kubernetes. With the help of Helm we can standardize the deployments and offer easy one click/command deployments to users and developers. The developers have the possibility to customize options like size, version, etc.

Are StatefulSets required?

StatefulSets are required in Kubernetes to scale stateful applications.  Using StatefulSets, PostgreSQL can now be easily scaled with a single command.

Why do we need Trident?

Trident enables dynamic provisioning of storage volumes, also known as persistent volumes or PVs, in Kubernetes. This empowers the developers to provision storage for their application in a self-service manner and on-demand.

Setup

What does our environment look like?

  • K8S: v1.8.4
  • Helm: v2.7.2
  • OS: Ubuntu v16.04
  • PostgreSQL: CrunchyData
  • NetApp Trident: v18.01

Are there any pre-requisites?

  • Working Kubernetes/OpenShift  (K8S 1.6+ or OpenShift 3.6+) environment.
  • Helm server and client is installed
  • Trident, installed and configured with at least one StorageClass. More info here
  • Define a default StorageClass
  • Download our sample Helm chart from GitHub

Install

Using Helm simplifies how you deploy/install applications on Kubernetes. Helm helps us create templates which act as a standard deployments for the users. Users can deploy this standard deployment by using just a single command.

If users want to customize their deployment they must copy a provided yaml and specify the changes they would like to see, e.g. changing the size or version of PostgreSQL from the standard deployment.

Single command (without any customization)

Installation with customization

Copy postgresql-replicaset/values.yaml and update per your requirements (storage class, size, image etc)

Then have Helm deploy the customized application:

Scale

Scaling an application deployed using Helm happens the same way as any other StatefulSet.

Cleanup

Resources

Kapil Arora
Cloud Platform Architect at NetApp
Kapil Arora is a cloud platform architect specialising in OpenStack, Containers and Enterprise Storage. He helps customers with proof of concept implementations and production deployments and focusses on innovation, evangelisation, and promoting the benefits of NetApp storage and software in cloud computing and containerised environments. He has experience working with many big organisations like SAP, BBVA and Deutsche Telekom in Europe and is an active speaker at OpenStack events and conferences. He is very interested in topics like File-share services, Backup and Recovery, Database Applications, and Persistent Storage for Containers. He has 10 years of IT industry experience including close to 8 years in the Storage industry. Kapil is also a Java and Python programmer and has a Bachelors degree in Information Technology.

Leave a Reply