Staging instance, all changes can be removed at any time

Skip to content

cloudnative-pg: Start managing dbs within kuberrnetes

Antoine R. Dumont requested to merge postgresql-with-cloudnative-pg into staging

(This is reviewable) Marked as draft as I'm currently just improving on nitpicks.

This:

  • adds a cluster-configuration template to be able to install cloudnative-pg operator in a kube cluster
  • adds a cluster-component template to install a postgresql cluster within a kube cluster (through the pg operator)
  • finally activates 2 postgresql clusters using the (small) secondary dbs from staging to populate such dbs.

This is currently running in the test-staging-rke2 cluster.

[1] https://argocd.internal.admin.swh.network/applications/test-staging-rke2-cluster-components?operation=false&conditions=false&resource=

helm diff: Activate the cloudnative-pg operator
make ccf-helm-diff | colordiff
colordiff 1.0.21 (http://www.colordiff.org/)
(C)2002-2022 Dave Ewart, davee@sungate.co.uk

Switched to branch 'production'
Switched to branch 'postgresql-with-cloudnative-pg'
[cluster-configuration] Comparing changes between branches production and postgresql-with-cloudnative-pg...
Your branch is up to date with 'origin/production'.
[cluster-configuration] Generate config in production branch for cluster-configuration/values/admin-rke2.yaml...
[cluster-configuration] Generate config in production branch for cluster-configuration/values/archive-production-rke2.yaml...
[cluster-configuration] Generate config in production branch for cluster-configuration/values/archive-staging-rke2.yaml...
[cluster-configuration] Generate config in production branch for cluster-configuration/values/gitlab-production.yaml...
[cluster-configuration] Generate config in production branch for cluster-configuration/values/gitlab-staging.yaml...
[cluster-configuration] Generate config in production branch for cluster-configuration/values/rancher.yaml...
[cluster-configuration] Generate config in production branch for cluster-configuration/values/test-staging-rke2.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/admin-rke2.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/archive-production-rke2.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/archive-staging-rke2.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/gitlab-production.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/gitlab-staging.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/rancher.yaml...
[cluster-configuration] Generate config in postgresql-with-cloudnative-pg branch for cluster-configuration/values/test-staging-rke2.yaml...


------------- diff for cluster-configuration/values/admin-rke2.yaml -------------

No differences


------------- diff for cluster-configuration/values/archive-production-rke2.yaml -------------

No differences


------------- diff for cluster-configuration/values/archive-staging-rke2.yaml -------------

No differences


------------- diff for cluster-configuration/values/gitlab-production.yaml -------------

No differences


------------- diff for cluster-configuration/values/gitlab-staging.yaml -------------

No differences


------------- diff for cluster-configuration/values/rancher.yaml -------------

No differences


------------- diff for cluster-configuration/values/test-staging-rke2.yaml -------------

--- /tmp/swh-chart.cluster-configuration.jf85umk6/test-staging-rke2.yaml.before 2024-06-06 11:18:51.584296289 +0200
+++ /tmp/swh-chart.cluster-configuration.jf85umk6/test-staging-rke2.yaml.after  2024-06-06 11:18:51.824288726 +0200
@@ -79,20 +79,45 @@
       prune: false
       selfHeal: false
     syncOptions:
     - RespectIgnoreDifferences=true
   ignoreDifferences:
     - group: cert-manager.io
       kind: Certificate
       jqPathExpressions:
         - .spec.duration
 ---
+# Source: Argocd applications commonly used in to configure a SWH cluster/templates/cloudnative-pg/operator-application.yaml
+apiVersion: argoproj.io/v1alpha1
+kind: Application
+metadata:
+  name: test-staging-rke2-cnpg-operator
+  namespace: argocd
+spec:
+  revisionHistoryLimit: 2
+  project: default
+  source:
+    chart: cloudnative-pg
+    repoURL: https://cloudnative-pg.github.io/charts
+    targetRevision: 0.21.4
+    helm:
+      # must match the application name (https://github.com/argoproj/argo-cd/issues/2871)
+      releaseName: test-staging-rke2-cnpg-operator
+
+  destination:
+    server: https://rancher.euwest.azure.internal.softwareheritage.org/k8s/clusters/c-m-hb9j7h5g
+    namespace: "cnpg-system"
+  syncPolicy:
+    automated:
+      prune: false
+      selfHeal: false
+---
 # Source: Argocd applications commonly used in to configure a SWH cluster/templates/cluster-configuration-application.yaml
 # Declare the argocd application to apply raw yamls on the cluster
 # Yamls are stored on the k8s-cluster-config repository in the `clusterName` directory
 apiVersion: argoproj.io/v1alpha1
 kind: Application
 metadata:
   name: test-staging-rke2-configuration-application
   namespace: argocd
 spec:
   project: default
helm diff: Install the postgresql cluster in test-staging-rke2
make cc-helm-diff | colordiff
colordiff 1.0.21 (http://www.colordiff.org/)
(C)2002-2022 Dave Ewart, davee@sungate.co.uk

Switched to branch 'production'
Switched to branch 'postgresql-with-cloudnative-pg'
[cluster-components] Comparing changes between branches production and postgresql-with-cloudnative-pg...
Your branch is up to date with 'origin/production'.
[cluster-components] Generate config in production branch for cluster-components/values/admin-rke2.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/archive-production-rke2.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/archive-staging-rke2.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/gitlab-production.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/gitlab-staging.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/minikube.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/rancher.yaml...
[cluster-components] Generate config in production branch for cluster-components/values/test-staging-rke2.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/admin-rke2.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/archive-production-rke2.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/archive-staging-rke2.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/gitlab-production.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/gitlab-staging.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/minikube.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/rancher.yaml...
[cluster-components] Generate config in postgresql-with-cloudnative-pg branch for cluster-components/values/test-staging-rke2.yaml...


------------- diff for cluster-components/values/admin-rke2.yaml -------------

No differences


------------- diff for cluster-components/values/archive-production-rke2.yaml -------------

No differences


------------- diff for cluster-components/values/archive-staging-rke2.yaml -------------

No differences


------------- diff for cluster-components/values/gitlab-production.yaml -------------

No differences


------------- diff for cluster-components/values/gitlab-staging.yaml -------------

No differences


------------- diff for cluster-components/values/minikube.yaml -------------

No differences


------------- diff for cluster-components/values/rancher.yaml -------------

No differences


------------- diff for cluster-components/values/test-staging-rke2.yaml -------------

--- /tmp/swh-chart.cluster-components.csWTqEeP/test-staging-rke2.yaml.before    2024-06-06 11:24:55.868599672 +0200
+++ /tmp/swh-chart.cluster-components.csWTqEeP/test-staging-rke2.yaml.after     2024-06-06 11:24:56.280581954 +0200
@@ -68,10 +68,139 @@
         - sendResolved: true
           url: https://alertmanager-irc-relay.internal.admin.swh.network/swh-sysadm
           httpConfig:
             basicAuth:
               username:
                 key: user
                 name: alertmanager-irc-relay-config
               password:
                 key: password
                 name: alertmanager-irc-relay-config
+---
+# Source: cluster-config/templates/cloudnative-pg/cluster.yaml
+apiVersion: postgresql.cnpg.io/v1
+kind: Cluster
+metadata:
+  name: staging-secondary-dbs
+  namespace: cnpg
+spec:
+  instances: 3
+  # Rolling update strategy:
+  # - unsupervised: automated update of the primary once all
+  #                 replicas have been upgraded (default)
+  # - supervised: requires manual supervision to perform
+  #               the switchover of the primary
+  primaryUpdateStrategy: unsupervised
+  enableSuperuserAccess: true
+  affinity:
+
+    nodeAffinity:
+      requiredDuringSchedulingIgnoredDuringExecution:
+        nodeSelectorTerms:
+        - matchExpressions:
+          - key: swh/storage
+            operator: In
+            values:
+            - "true"
+
+  bootstrap:
+    initdb:
+
+      # The following optionals are the equivalent of flags passed to initdb
+      # commented because those are already the default values
+      # --encoding
+      # encoding: UTF8
+      # --lc-ctype
+      # localeCType: C
+      # --lc-collate
+      # localeCollate: C
+      # -k option to enable checksums on data pages to help detect I/O
+      # -corruption
+      dataChecksums: true
+      import:
+        # 2 types possibles
+        # - monolith: for one cluster with all dbs
+        # - microservice (recommended): one db per cluster (lots of pods)
+        type: monolith
+        databases:
+          - swh-blocking
+          - swh-deposit
+          - swh-masking
+          - swh-vault
+          - swh-web
+
+        roles:
+          - "*"
+
+        source:
+          externalCluster: cluster-staging-db1
+  externalClusters:
+    - connectionParameters:
+        host: db1.internal.staging.swh.network
+        port: "5433"
+        user: postgres
+      name: cluster-staging-db1
+      password:
+        key: password
+        name: cluster-staging-db1-postgres-user-credential
+
+  # Parameters and pg_hba configuration will be append
+  # to the default ones to make the cluster work
+  postgresql:
+    parameters:
+      max_worker_processes: "60"
+    pg_hba:
+    - host all all all md5
+
+
+  storage:
+    storageClass: local-persistent
+    size: 1Gi
+  # walStorage:
+  #   storageClass: local-persistent
+  #   size: 1Gi
+
+  monitoring:
+    enablePodMonitor: true
+  # Backup properties
+  # This assumes a local minio setup
+  backup:
+    volumeSnapshot:
+      className: local-persistent
+      online: true
+      # onlineConfiguration:
+      #   immediateCheckpoint: true
+      #   waitForArchive: false
+    retentionPolicy: "30d"
+    barmanObjectStore:
+      data:
+        additionalCommandArgs:
+        - --min-chunk-size=5MB
+        - --read-timeout=60
+        - -vv
+      destinationPath: s3://test/
+      endpointURL: https://minio.admin.swh.network
+      s3Credentials:
+        accessKeyId:
+          key: ACCESS_KEY_ID
+          name: minio-test-bucket-secret
+        secretAccessKey:
+          key: ACCESS_SECRET_KEY
+          name: minio-test-bucket-secret
+      wal:
+        compression: gzip
+---
+# Source: cluster-config/templates/cloudnative-pg/scheduled-backup.yaml
+apiVersion: postgresql.cnpg.io/v1
+kind: ScheduledBackup
+metadata:
+  name: backup-daily-midnight
+  namespace: cnpg
+spec:
+  schedule: 0 0 0 * * *
+  # backupOwnerReference
+  # none: no owner reference for created backup objects (same behavior as before the field was introduced)
+  # self: sets the Scheduled backup object as owner of the backup
+  # cluster: set the cluster as owner of the backup
+  backupOwnerReference: self
+  cluster:
+    name: staging-secondary-dbs

Refs. swh/infra/sysadm-environment#5311 (closed)

Edited by Antoine R. Dumont

Merge request reports

Loading