Installing a PostgreSQL Operator on Kubernetes with Istio and Longhorn
A Step-by-Step Tutorial

In this tutorial, we will walk through the process of installing a PostgreSQL Operator on a Kubernetes cluster with Istio and Longhorn. PostgreSQL operators make it easy to manage and deploy PostgreSQL clusters in a Kubernetes environment, allowing you to seamlessly integrate your databases with applications running on your cluster. Let’s dive in and set up the PostgreSQL Operator, so you can take advantage of this powerful tool!
Prerequisites:
- A Kubernetes cluster with Istio and Longhorn installed
- Access to the command line interface (CLI)
- Basic understanding of Kubernetes and PostgreSQL

Step 1:
Install the PostgreSQL Operator
First, we will install Zalando’s PostgreSQL Operator using the CLI. Clone the Zalando’s PostgreSQL Operator repository and change to the cloned directory:
git clone https://github.com/zalando/postgres-operator.git
cd postgres-operatorNext, apply the provided YAML manifests to install the PostgreSQL Operator:
kubectl apply -f manifests/configmap.yaml kubectl apply -f manifests/operator-service-account-rbac.yaml kubectl apply -f manifests/postgres-operator.yaml
Step 2:
Configure Istio and Longhorn
Before we proceed, we need to configure Istio and Longhorn to work with the PostgreSQL Operator. Create the following custom resource to create a DestinationRule for the PostgreSQL Operator:
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: postgres-operator # change this (optional)
namespace: default
spec:
host: postgres-operator.default.svc.cluster.local
trafficPolicy:
tls:
mode: DISABLENext, configure Longhorn by creating a StorageClass for the PostgreSQL Operator:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: longhorn-postgres # change this (optional)
provisioner: driver.longhorn.io
parameters:
numberOfReplicas: "3"
staleReplicaTimeout: "2880"
fromBackup: ""
allowVolumeExpansion: trueStep 3:
Deploy a PostgreSQL Cluster
Now that the PostgreSQL Operator is installed and configured, we can deploy a PostgreSQL cluster. Create a postgresql custom resource using the following YAML template:
apiVersion: acid.zalan.do/v1
kind: postgresql
metadata:
name: my-postgres-cluster
namespace: default
spec:
teamId: "my-team"
volume:
size: 10Gi
storageClass: longhorn-postgres
numberOfInstances: 2
users:
myuser: [] # grants no privileges
databases:
mydb: myuser
postgresql:
version: "13"Apply the custom resources to deploy the PostgreSQL cluster from step 2 and 3.
Congratulations! You have successfully installed a PostgreSQL Operator on a Kubernetes cluster with Istio and Longhorn, making it ready for use with any application deployed on your cluster. This setup provides a solid foundation for managing and scaling your PostgreSQL databases in a Kubernetes environment.
If there’s enough interest in this topic, I might just whip up a complete script for deploying the PostgreSQL Operator with a single command. So, if you want to see that script in action, don’t forget to give this article some love! Let’s see if we can reach 1000 claps, and who knows, maybe
If you’d like to spin up a few virtual machines, or even deploy your production environment on the internet, I’d recommend Vultr, as they are affordable and their infrastructure just works.
Please consider signing up with my referral link, it will help me out as well
If you don’t use Vultr and find the post useful, consider buying me a coffee.
Update 17/5/2023: As of v1.10, using an ingress to access the operator’s UI, is broken. I can confirm, that it is working on v1.9.
Issue open at #2302





