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.
- 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!!
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)
# 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
- get all pods in the
namespace zalando-postgres
with the operator labelname=postgres-operator
kubectl get pod -l name=postgres-operator --namespace zalando-postgres
- 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 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
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
- 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>
kubectl delete postgresql acid-minimal-cluster --namespace zalando-postgres