Umberto D'Ovidio

Deploying a Postgres cluster in Rancher

Deploying a Postgres cluster on Kubernetes has become quite easy thanks to the Postgres Operator. Let’s see how this can be done with a rancher cluster.

Essentially, it’s sufficient to follow the quickstart tutorial. There is only a caveat. I am running a bare metal K3s cluster. By default, the operator will try to create a PersistentVolumeClaim with the default storage class of the cluster. Problem is, my cluster didn’t have a default storage class. The PersistentVolumeClaim fails, and looking at the events it becomes clear what’s the problem: FailedBinding: no persistent volumes available for this claim and no storage class is set.

Failed persistent volume binding

To solve this, I used the Rancher Local Path Provisioner which is good enough since the cluster I’m working with is used only for testing. We first create the storage class with the following command:

1kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml

And then we set it as default storage class with

1kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Here’s a recap of all commands I used to deploy the postgres cluster:

1# setup default storage class to be local-path
2kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
3kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
4# deploy the operator
5kubectl apply -k github.com/zalando/postgres-operator/manifests
6# deploy a minimal cluster
7kubectl create -f manifests/minimal-postgres-manifest.yaml