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