Skip to content

Latest commit

 

History

History
101 lines (72 loc) · 4.23 KB

Readme.md

File metadata and controls

101 lines (72 loc) · 4.23 KB

Custom Postgres Operator

This repository contains a custom setup for an HA Postgres cluster, based on Postgres Operator from Patroni. The manifest folder only contains the minimum needed YAML files for the setup.

The Cluster runs on an K8s Cluster which is managed by Rancher.

Setup on K8s cluster(Rancher)

  • Projectname: zalando-postgres
  • Namespace: zalando-postgres
  • 4 Nodes(per Node 4Cores and 8GB RAM)
    • 3 master and 3 worker nodes
  • Storage Provisioner: Longhorn
    • Cluster and PVC Snapshots to minio
  • LoadBalancer: Metallb
    • access actual Postgres master and standbys over external-IP and specified port
    • required VPN connection!!

Installation

The installation will be executed by applying manifests in a specific order, based on the operator installation from Patroni. The setup is deployed to an specific namespace named zalando-postgres, which must be ceated first on the K8s cluster. You also can setup the operator(+Postgres cluster) with Helm chart or Operator Lifecycle Manager. (fyi: you can also set the current-context for kubectl, here ns=zalando-postgres for example)

Create the operator

# operator configuration
kubectl create -f manifests/configmap.yaml --namespace zalando-postgres
# identity and permissions
kubectl create -f manifests/operator-service-account-rbac.yaml --namespace zalando-postgres
# deploy operator to K8s
kubectl create -f manifests/postgres-operator.yaml --namespace zalando-postgres

Check operator status

  • get all pods in the namespace zalando-postgres with the operator label name=postgres-operator
kubectl get pod -l name=postgres-operator --namespace zalando-postgres

Create Postgres cluster

  • create a Postgres cluster from postgres manifest with the specified values, like databases, users and postgresql.conf parameters
kubectl create -f manifests/minimal-postgres-manifest.yaml --namespace zalando-postgres

Check Postgres cluster status

# check the deployed cluster
kubectl get postgresql
# check created database pods with spilo-role (master, replica)
kubectl get pods -l application=spilo -L spilo-role --namespace zalando-postgres
# check created service resources and get ext. loadbalancer ip and port
kubectl get svc -l application=spilo -L spilo-role --namespace zalando-postgres

Update Pod Manifest

You can update the Postgres cluster with the manifest file or directly with psql-client.

  • After editting Postgres cluster file apply the modified configuration(with apply the whole object while be updated)
    • kubectl apply -f manifests/minimal-postgres-manifest.yaml --namespace zalando-postgres
  • Restart(Reload?) Patroni
    • kubectl exec -i <Pod-Name> supervisorctl restart patroni --namespace zalando-postgres

Connect to Postgres master

  • required pg_hba.conf entry for the external LoadBalancer IP
psql -h <LoadBalancer-IP> -p <LoadBalancer-Port>  -d <databasename> -U <databaseuser>
  • connect directly from shell in Rancher
psql -d <databasename> -U <databaseuser>

Delete Postgres Cluster

kubectl delete postgresql acid-minimal-cluster --namespace zalando-postgres

Referenced