diff --git a/kubernetes/README.md b/kubernetes/README.md index 585de7e..00edfd1 100644 --- a/kubernetes/README.md +++ b/kubernetes/README.md @@ -512,7 +512,7 @@ kubectl get secret wildcard-cert-secret --namespace=cert-manager -o yaml \ # The configMap contains the app.ini file values for gitea envsubst < gitea/configMap.yaml | kubectl apply -n gitea -f - -helm install gitea gitea-charts/gitea -f gitea/values.yaml \ +helm upgrade --install gitea gitea-charts/gitea -f gitea/values.yaml \ --namespace gitea \ --atomic \ --set ingress.hosts[0].host=$GITEA_HOST \ @@ -706,10 +706,21 @@ envsubst < cloud-native-pg/backup-recovery.yaml | kubectl apply -n immich -f - ## Create a new PostgreSQL cluster from existing Database To create a new PostgreSQL cluster from an existing database, you can use the -`create-cluster.yaml` template. This template allows you to create a new +`create-cluster-main.yaml` as template. This template allows you to create a new PostgreSQL cluster from an existing database by specifying the necessary configurations and parameters in the YAML file. +This below example shows how I created a new PostgreSQL cluster from my existing +main postgres database. The new cluster is created in the `postgres` namespace. +The existing postgres database will be deprecated and removed in the future. + +```bash +source .env +envsubst < cloud-native-pg/secrets.yaml | kubectl apply -n postgres -f - +envsubst < cloud-native-pg/create-cluster-main.yaml | kubectl apply -n postgres -f - +kubectl apply -f cloud-native-pg/pg-main-backup.yaml -n postgres +``` + # Immich Self-hosted Photo and Video Backup Solution Immich is a self-hosted photo and video backup solution that is deployed in diff --git a/kubernetes/cloud-native-pg/create-cluster-main.yaml b/kubernetes/cloud-native-pg/create-cluster-main.yaml new file mode 100644 index 0000000..095fa56 --- /dev/null +++ b/kubernetes/cloud-native-pg/create-cluster-main.yaml @@ -0,0 +1,49 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: master-postgres +spec: + instances: 1 + bootstrap: + initdb: + import: + type: monolith + databases: + - giteadb + - reservemaster + roles: + - gitea + - postgres + - taqi + source: + externalCluster: pg-main + storage: + size: 5Gi + storageClass: longhorn-2x + externalClusters: + - name: pg-main + connectionParameters: + host: 192.168.1.142 + user: postgres + dbname: postgres + password: + name: my-postgres-postgresql + key: postgres-password + # Backup properties for MinIO + backup: + barmanObjectStore: + destinationPath: s3://pgmain + endpointURL: ${MINIO_ENDPOINT_URL} + s3Credentials: + accessKeyId: + name: minio-creds + key: ACCESS_KEY_ID + secretAccessKey: + name: minio-creds + key: ACCESS_SECRET_KEY + wal: + compression: gzip + data: + compression: gzip + retentionPolicy: "15d" + diff --git a/kubernetes/cloud-native-pg/pg-main-backup.yaml b/kubernetes/cloud-native-pg/pg-main-backup.yaml new file mode 100644 index 0000000..6077c18 --- /dev/null +++ b/kubernetes/cloud-native-pg/pg-main-backup.yaml @@ -0,0 +1,10 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: ScheduledBackup +metadata: + name: pg-main-backup +spec: + immediate: true + schedule: "0 0 0 * * *" # At midnight every day + backupOwnerReference: self + cluster: + name: master-postgres diff --git a/kubernetes/cloud-native-pg/pgmain-svc.yaml b/kubernetes/cloud-native-pg/pgmain-svc.yaml new file mode 100644 index 0000000..b5aa31f --- /dev/null +++ b/kubernetes/cloud-native-pg/pgmain-svc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: pgmain-svc +spec: + type: LoadBalancer + ports: + - port: 5432 + targetPort: 5432 + selector: + cnpg.io/cluster: master-postgres +