CloudNativePGの1.21.0がリリースされたようなのでアップグレード。
Upgrading Operator
1.21.0のoperator manifestを適用。
kubectl apply -f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.21/releases/cnpg-1.21.0.yaml
namespace/cnpg-system unchanged
customresourcedefinition.apiextensions.k8s.io/backups.postgresql.cnpg.io configured
customresourcedefinition.apiextensions.k8s.io/clusters.postgresql.cnpg.io configured
customresourcedefinition.apiextensions.k8s.io/poolers.postgresql.cnpg.io configured
customresourcedefinition.apiextensions.k8s.io/scheduledbackups.postgresql.cnpg.io configured
serviceaccount/cnpg-manager unchanged
clusterrole.rbac.authorization.k8s.io/cnpg-manager configured
clusterrolebinding.rbac.authorization.k8s.io/cnpg-manager-rolebinding unchanged
configmap/cnpg-default-monitoring configured
service/cnpg-webhook-service unchanged
deployment.apps/cnpg-controller-manager configured
mutatingwebhookconfiguration.admissionregistration.k8s.io/cnpg-mutating-webhook-configuration configured
validatingwebhookconfiguration.admissionregistration.k8s.io/cnpg-validating-webhook-configuration configured
Deploying PostgreSQL16 Cluster
新クラスタ用のnamespaceを作成
kubectl create ns cnpg161
S3互換ストレージ(DO Spaces)へのバックアップ用クレデンシャルシークレットを作成
kubectl -n cnpg161 create secret generic backup-creds --from-literal=ACCESS_KEY_ID=XXXXXXXXX123456789 --from-literal=ACCESS_SECRET_KEY=YYYYYYYY123456789
マニフェストファイルを作成
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cnpg161
namespace: cnpg161
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:16.0
instances: 2
minSyncReplicas: 1
maxSyncReplicas: 1
postgresql:
parameters:
shared_buffers: 128MB
storage:
storageClass: do-block-storage-xfs
size: 1Gi
monitoring:
enablePodMonitor: true
backup:
barmanObjectStore:
destinationPath: "s3://dok8s-space1/cnpg-backup/"
endpointURL: "https://sgp1.digitaloceanspaces.com"
s3Credentials:
accessKeyId:
name: backup-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: backup-creds
key: ACCESS_SECRET_KEY
wal:
compression: gzip
encryption: AES256
data:
compression: gzip
encryption: AES256
immediateCheckpoint: false
jobs: 2
retentionPolicy: "30d"
---
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: backup-cnpg161
spec:
schedule: "1 1 1 * * *"
backupOwnerReference: self
cluster:
name: cnpg161
作成したマニフェストを適用
kubectl -n cnpg161 apply -f cluster-cnpg161.yml
ステータス確認
kubectl -n cnpg161 get all,pvc,scheduledbackups.postgresql.cnpg.io
NAME READY STATUS RESTARTS AGE
pod/cnpg161-1 1/1 Running 1 (4h17m ago) 4h24m
pod/cnpg161-2 1/1 Running 0 4h23m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cnpg161-r ClusterIP 10.245.253.129 <none> 5432/TCP 4h25m
service/cnpg161-ro ClusterIP 10.245.192.51 <none> 5432/TCP 4h25m
service/cnpg161-rw ClusterIP 10.245.180.229 <none> 5432/TCP 4h25m
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/cnpg161-1 Bound pvc-711a4b82-1fb6-48da-ae04-4756e24655c2 1Gi RWO do-block-storage-xfs 4h25m
persistentvolumeclaim/cnpg161-2 Bound pvc-7aa59eeb-e353-40a5-953e-fcbea8371aff 1Gi RWO do-block-storage-xfs 4h24m
NAME AGE CLUSTER LAST BACKUP
scheduledbackup.postgresql.cnpg.io/backup-cnpg161 23m cnpg161 18m
クラスタのステータス確認
kubectl cnpg -n cnpg161 status cnpg161
Cluster Summary
Name: cnpg161
Namespace: cnpg161
System ID: 7291519154989084691
PostgreSQL Image: ghcr.io/cloudnative-pg/postgresql:16.0
Primary instance: cnpg161-2
Primary start time: 2023-10-19 04:25:51 +0000 UTC (uptime 4h19m51s)
Status: Cluster in healthy state
Instances: 2
Ready instances: 2
Current Write LSN: 0/37000D80 (Timeline: 2 - WAL File: 000000020000000000000037)
Certificates Status
Certificate Name Expiration Date Days Left Until Expiration
---------------- --------------- --------------------------
cnpg161-ca 2024-01-17 04:13:00 +0000 UTC 89.81
cnpg161-replication 2024-01-17 04:13:00 +0000 UTC 89.81
cnpg161-server 2024-01-17 04:13:00 +0000 UTC 89.81
Continuous Backup status
First Point of Recoverability: 2023-10-19T04:27:03Z
Working WAL archiving: OK
WALs waiting to be archived: 0
Last Archived WAL: 000000020000000000000036 @ 2023-10-19T08:43:50.729816Z
Last Failed WAL: -
Streaming Replication status
Replication Slots Enabled
Name Sent LSN Write LSN Flush LSN Replay LSN Write Lag Flush Lag Replay Lag State Sync State Sync Priority Replication Slot
---- -------- --------- --------- ---------- --------- --------- ---------- ----- ---------- ------------- ----------------
cnpg161-1 0/37000D80 0/37000D80 0/37000D80 0/37000D80 00:00:00 00:00:00 00:00:00 streaming quorum 1 active
Unmanaged Replication Slot Status
No unmanaged replication slots found
Instances status
Name Database Size Current LSN Replication role Status QoS Manager Version Node
---- ------------- ----------- ---------------- ------ --- --------------- ----
cnpg161-2 67 MB 0/37000D80 Primary OK BestEffort 1.21.0 dok8s-pool-ypy56
cnpg161-1 67 MB 0/37000D80 Standby (sync) OK BestEffort 1.21.0 dok8s-pool-ypy5t
接続確認
kubectl cnpg -n cnpg psql cnpg161
postgres=# select version();
version
-----------------------------------------------------------------------------------------------------------------------------
PostgreSQL 16.0 (Debian 16.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
(1 row)