avatarAdam Poniatowski

Summary

This web content provides a comprehensive guide on installing a PostgreSQL Operator on a Kubernetes cluster, integrating it with Istio and Longhorn for efficient database management and deployment.

Abstract

The article is a step-by-step tutorial for setting up a PostgreSQL Operator within a Kubernetes environment that is enhanced with Istio service mesh and Longhorn storage. It begins by outlining the prerequisites, which include a Kubernetes cluster pre-installed with Istio and Longhorn, CLI access, and a basic understanding of Kubernetes and PostgreSQL. The guide then proceeds through three main steps: installing the PostgreSQL Operator using Zalando's repository, configuring Istio and Longhorn to work with the operator, and finally, deploying a PostgreSQL cluster with custom resource definitions. The tutorial emphasizes the ease of managing and deploying PostgreSQL clusters in Kubernetes with the operator, and it concludes with a call to action for reader engagement and support for the author's work.

Opinions

  • The author expresses enthusiasm about the PostgreSQL Operator's ability to simplify database management within Kubernetes.
  • There is an implied opinion that using Istio and Longhorn provides a robust and scalable infrastructure for PostgreSQL deployments.
  • The author suggests a sense of community and reader engagement by mentioning the possibility of creating a deployment script based on reader interest and interaction with the article.
  • A recommendation for Vultr's hosting services is made, indicating a positive opinion of their affordability and reliability.
  • The author seeks support from readers, either by using their referral link for Vultr or by donating through a "buy me a coffee" link, suggesting a personal investment in the content's usefulness to the community.
  • An update regarding a known issue with the operator's UI access when using a specific version indicates a commitment to keeping the content current and helpful.

Installing a PostgreSQL Operator on Kubernetes with Istio and Longhorn

A Step-by-Step Tutorial

From: postgresql wiki

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
From: github.com/zalando/postgres-operator

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-operator

Next, 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: DISABLE

Next, 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: true

Step 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

Kubernetes
Postgresql
K8s
Istio
Longhorn
Recommended from ReadMedium
avatarPraneeth Bilakanti
Kubernetes Volumes

Kubernetes Volumes

34 min read