Website
GitHub
Docs
Main Features
Release 1.26
Kubectl Plugin
Quick Start
Services
Backups
Backup Plugin
Failure
Failover
Reading Logs
Logs Plugin
Rolling Upgrades
PostgreSQL Upgrades
Recovery
Replica Cluster
Distributed Topology
Github Discussions
Blog
Slack
Linkedin
kc(){
## Custom Kubectl for different regions
if [[ $# -lt 1 ]]
then
echo "kc <REGION> <command>"
return 1
fi
REGION=${1}
shift
kubectl --context=kind-k8s-${REGION} $@
}
kcnpg(){
## Custom Kubectl for different regions
if [[ $# -lt 1 ]]
then
echo "kcnpg <REGION> <command>"
return 1
fi
REGION=${1}
shift
kubectl cnpg --context=kind-k8s-${REGION} $@
}
for region in {eu,us}
do
eval alias k${region}=\"kc \${region}\"
eval alias kcnpg${region}=\"kcnpg \${region}\"
donegit clone [email protected]:cloudnative-pg/cnpg-playground.gitsudo sysctl fs.inotify.max_user_watches=524288 fs.inotify.max_user_instances=512cd cnpg-playground
./scripts/setup.shexport KUBECONFIG=<path-to>/cnpg-playground/k8s/kube-config.yaml
kubectl config use-context kind-k8s-eu. ./bash_aliases.shcurl -sSfL \
https://github.com/cloudnative-pg/cloudnative-pg/raw/main/hack/install-cnpg-plugin.sh | \
sudo sh -s -- -b /usr/local/binkubectl cnpg install generate --control-plane --version 1.25.1 \
| kubectl apply -f - --server-sidekubectl get pods -wcat <<EOF > ./cluster-example.yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 3
storage:
size: 1Gi
EOFkubectl apply -f ./cluster-example.yamlkubectl get clusters,pods,pvc,svc,ep,secretscat <<EOF > ./cluster-example-backup.yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example-backup
spec:
instances: 3
storage:
size: 1Gi
backup:
barmanObjectStore:
destinationPath: s3://backups/
endpointURL: http://minio-eu:9000
s3Credentials:
accessKeyId:
name: minio-eu
key: ACCESS_KEY_ID
secretAccessKey:
name: minio-eu
key: ACCESS_SECRET_KEY
wal:
compression: gzip
EOFkubectl apply -f ./cluster-example-backup.yamlkubectl cnpg status cluster-example-backupkubectl cnpg psql cluster-example-backup -- appCREATE TABLE numbers(x int);
INSERT INTO numbers (SELECT generate_series(1,1000000));
\qkubectl cnpg backup cluster-example-backupkubectl get backup
kubectl get backup -o yaml
kubectl cnpg status cluster-example-backup# find primary
kubectl get cluster cluster-example-backupkubectl get pods -wkubectl delete pod cluster-example-backup-#kubectl cnpg status cluster-example-backup# find primary
kubectl get cluster cluster-example-backupkubectl get pods -wkubectl delete pod,pvc cluster-example-backup-#kubectl cnpg status cluster-example-backupkubectl logs cluster-example-backup-#kubectl cnpg logs cluster cluster-example-backup \
| kubectl cnpg logs pretty# Monitor resources
kubectl get pod -n cnpg-systemkubectl cnpg install generate --control-plane --version 1.26.0 \
| kubectl apply -f - --server-side# Create cluster example YAML file
cat <<EOF > ./cluster-example.yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:16.3
instances: 3
storage:
size: 1Gi
EOFkubectl get pods -wkubectl apply -f ./cluster-example.yamlsed -i 's/16\.3/16\.9/' cluster-example.yaml
cat cluster-example.yamlkubectl apply -f ./cluster-example.yaml \
&& kubectl cnpg status cluster-example# Edit Cluster manifest file and verify
sed -i 's/16\.9/17\.5/' cluster-example.yaml
cat cluster-example.yamlkubectl apply -f ./cluster-example.yaml \
&& kubectl cnpg status cluster-example# Create a cluster manifest with bootstrap method: recovery
cat <<EOF > ./cluster-recovery.yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-recovery
spec:
instances: 3
storage:
size: 1Gi
bootstrap:
recovery:
source: origin
externalClusters:
- name: origin
barmanObjectStore:
serverName: cluster-example-backup
destinationPath: s3://backups/
endpointURL: http://minio-eu:9000
s3Credentials:
accessKeyId:
name: minio-eu
key: ACCESS_KEY_ID
secretAccessKey:
name: minio-eu
key: ACCESS_SECRET_KEY
wal:
compression: gzip
EOFkubectl get pods -wkubectl apply -f ./cluster-recovery.yamlkubectl cnpg status cluster-recoverykubectl cnpg psql cluster-recovery -- appSELECT COUNT(*) numbers;# Ensure to connect to the k8s-eu cluster
kubectl config use-context kind-k8s-eukubectl apply -f <path-to>/cnpg-playground/demo/yaml/eu/pg-eu-legacy.yamlkubectl cnpg status pg-eukubectl cnpg backup pg-eu# Get context and set it
./scripts/info.sh
kubectl config use-context kind-k8s-uskubectl get pods -n cnpg-system
kubectl config current-contextkubectl cnpg install generate \
--control-plane | \
kubectl apply -f - --server-sidekubectl get deployment -n cnpg-system
kubectl get crd | grep cnpgkubectl get pods -wkubectl apply -f <path-to>/cnpg-playground/demo/yaml/us/pg-us-legacy.yamlkubectl cnpg status pg-uskubectl get cluster pg-us -o yaml
kubectl --context kind-k8s-eu get cluster pg-eu -o yaml# Monitor pods in both clusters
kubectl --context kind-k8s-eu get pods -w
kubectl --context kind-k8s-us get pods -wkubectl --context kind-k8s-eu edit cluster pg-eukubectl --context kind-k8s-eu get cluster pg-eu -o jsonpath='{.status.demotionToken}'kubectl --context kind-k8s-us edit cluster pg-us