Skip to content

Tips

Minimal cluster

This is the minimal cluster spec

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: sinbootstrap
spec:
  storage:
    storageClass: standard
    size: 1Gi

Recreate all the cluster nodes

  • Destroy 2 replicas
kubectl cnpg destroy MYCLUSTER ONE-REPLICA
kubectl cnpg destroy MYCLUSTER ANOTHER-REPLICA

Once they are ok, promote a replica to be primary

kubectl cnpg promote MYCLUSTER ONE-REPLICA

Once is prometed, destroy the older primary

kubectl cnpg destroy MYCLUSTER OLD-PRIMARY

Info about primary replicas

Show the nodes where the replicas are located

kubectl get pod -A -l cnpg.io/instanceRole=primary -o custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,NODE:.spec.nodeName

Backups

List completed backups

kubectl get backups -o jsonpath='{range .items[?(@.status.phase=="completed")]}{.metadata.name}{"\n"}{end}'

List not completed backups

kubectl get backups -o jsonpath='{range .items[?(@.status.phase!="completed")]}{.metadata.name}{" - Status: "}{.status.phase}{"\n"}{end}'

List failed backups

kubectl get backups -o jsonpath='{range .items[?(@.status.phase=="failed")]}{.metadata.name}{"\n"}{end}'

List volume backup snaphots

kubectl get backups -o jsonpath='{range .items[?(@.spec.method=="volumeSnapshot")]}{.metadata.name}{"\n"}{end}'

Same but older thatn 30 days

kubectl get backups --sort-by=.metadata.creationTimestamp -o jsonpath='{range .items[?(@.spec.method=="volumeSnapshot")]}{.metadata.name}{"\n"}{end}' | head -n -30

Delete them, per namespace

for backup in $(kubectl get backups  --sort-by=.metadata.creationTimestamp -o jsonpath='{range .items[?(@.spec.method=="volumeSnapshot")]}{.metadata.name}{"\n"}{end}' | head -n -30); do kubectl delete backup $backup;done