Skip to content

Instantly share code, notes, and snippets.

@Rafisto
Created February 2, 2025 22:37
Show Gist options
  • Save Rafisto/b54d1251e5cfa78d3806706cb8a1b275 to your computer and use it in GitHub Desktop.
Save Rafisto/b54d1251e5cfa78d3806706cb8a1b275 to your computer and use it in GitHub Desktop.
Postgres Operator - Quickstart Guide

Source https://cloudnative-pg.io/

Install Operator

helm repo add cnpg https://cloudnative-pg.github.io/charts
helm upgrade --install postgres-operator -n postgres-operator cnpg/cloudnative-pg

Verify install

kubectl get po -n postgres-operator

Install cluster with operator

Install container

kubectl apply -f postgres.yaml
# get initial password
kubectl get secret -n postgres pgcluster-app -o yaml

Use cluster

## dba
kubectl exec -it -n postgres pgcluster-2 -- psql

## app
kubectl --namespace postgres exec --stdin --tty services/p  gcluster-rw -- bash

Uninstall cluster

kubectl delete -f postgres.yaml

Helm

Install

# standalone install
helm upgrade --install pgcluster -n postgres cnpg/cluster --values pgcluster.yaml
helm test --namespace postgres pgcluster

Uninstall

# standalone uninstall
helm uninstall pgcluster -n postgres
helm uninstall postgres-operator -n postgres-operator
# standalone cluster
type: postgresql
mode: standalone
version:
postgresql: "17"
cluster:
instances: 3
storage:
size: 1Gi
# via operator
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pgcluster
namespace: postgres
spec:
instances: 3
imageName: ghcr.io/cloudnative-pg/postgresql:17
storage:
size: 1Gi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment