Compare commits

..

2 Commits

13 changed files with 45 additions and 201 deletions

View File

@@ -1,14 +0,0 @@
apiVersion: v2
name: postgres-cluster-upgrade
version: 0.1.2
description: Chart for upgrading a cloudnative-pg cluster in the same namespace
keywords:
- database
- postgres
- upgrade
sources:
- https://github.com/cloudnative-pg/cloudnative-pg
maintainers:
- name: alexlebens
icon: https://avatars.githubusercontent.com/u/100373852?s=48&v=4
appVersion: v1.22.2

View File

@@ -1,19 +0,0 @@
## Introduction
[CloudNative PG](https://github.com/cloudnative-pg/cloudnative-pg)
CloudNativePG is the Kubernetes operator that covers the full lifecycle of a highly available PostgreSQL database cluster with a primary/standby architecture, using native streaming replication.
This chart bootstraps a [CNPG](https://github.com/cloudnative-pg/cloudnative-pg) cluster upgraade on a [Kubernetes](https://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
The process is designed to be used in conjunction with the [postgres-cluster](https://github.com/alexlebens/helm-charts/tree/main/charts/postgres-cluster) chart. The cluster in this chart connects to the orignal cluster, peforms an upgrade, then backups to the objectStore endpoint. Afterwards the upgrade cluster is removed and the orignal cluster bootstraps from the upgrade's backup.
## Prerequisites
- Kubernetes
- Helm
- CloudNative PG Operator
## Parameters
See the [values files](values.yaml).

View File

@@ -1,17 +0,0 @@
{{- if .Values.backup.inititeBackup }}
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: "postgresql-{{ .Release.Name }}-cluster-upgrade-backup"
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: "postgresql-{{ .Release.Name }}-cluster-upgrade-backup"
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Release.Name }}
spec:
method: barmanObjectStore
cluster:
name: "postgresql-{{ .Release.Name }}-cluster-upgrade"
{{- end }}

View File

@@ -1,68 +0,0 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: "postgresql-{{ .Release.Name }}-cluster-upgrade"
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: "postgresql-{{ .Release.Name }}-cluster-upgrade"
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Release.Name }}
spec:
imageName: "{{ .Values.cluster.image.repository }}:{{ .Values.cluster.image.tag }}"
instances: {{ .Values.cluster.instances }}
affinity:
enablePodAntiAffinity: true
topologyKey: kubernetes.io/hostname
postgresql:
parameters:
{{- toYaml .Values.cluster.parameters | nindent 6 }}
resources:
{{- toYaml .Values.cluster.resources | nindent 4 }}
storage:
storageClass: {{ .Values.cluster.storage.data.storageClass }}
size: {{ .Values.cluster.storage.data.size }}
walStorage:
storageClass: {{ .Values.cluster.storage.wal.storageClass }}
size: {{ .Values.cluster.storage.wal.size }}
monitoring:
enablePodMonitor: true
bootstrap:
initdb:
import:
type: {{ .Values.upgrade.importType }}
databases:
{{- toYaml .Values.upgrade.importDatabases | nindent 10 }}
source:
externalCluster: "postgresql-{{ .Release.Name }}-cluster"
externalClusters:
- name: "postgresql-{{ .Release.Name }}-cluster"
connectionParameters:
host: "postgresql-{{ .Release.Name }}-cluster-rw"
user: app
dbname: app
password:
name: "postgresql-{{ .Release.Name }}-cluster-app"
key: password
{{- if .Values.backup.backupEnabled }}
backup:
retentionPolicy: "{{ .Values.backup.retentionPolicy }}"
barmanObjectStore:
destinationPath: "s3://{{ .Values.backup.bucket }}/{{ .Values.cluster.name }}/postgresql/{{ .Release.Name }}-cluster"
endpointURL: {{ .Values.backup.endpointURL }}
serverName: "postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.backup.backupIndex }}"
s3Credentials:
accessKeyId:
name: "postgresql-{{ .Release.Name }}-cluster-backup-secret"
key: ACCESS_KEY_ID
secretAccessKey:
name: "postgresql-{{ .Release.Name }}-cluster-backup-secret"
key: ACCESS_SECRET_KEY
data:
compression: {{ .Values.cluster.compression }}
wal:
compression: {{ .Values.cluster.compression }}
{{- end }}

View File

@@ -1,37 +0,0 @@
cluster:
name:
image:
repository: ghcr.io/cloudnative-pg/postgresql
tag: 16.2
instances: 1
parameters:
shared_buffers: 128MB
max_slot_wal_keep_size: 2000MB
hot_standby_feedback: "on"
compression: snappy
resources:
requests:
memory: 512Mi
cpu: 100m
limits:
memory: 2Gi
cpu: 1500m
hugepages-2Mi: 512Mi
storage:
data:
storageClass:
size: 10Gi
wal:
storageClass:
size: 2Gi
upgrade:
importType: microservice
importDatabases:
- app
backup:
backupEnabled: false
inititeBackup: false
retentionPolicy: 3d
backupIndex: 1
endpointURL:
bucket:

View File

@@ -1,6 +1,6 @@
apiVersion: v2 apiVersion: v2
name: postgres-cluster name: postgres-cluster
version: 1.1.0 version: 2.0.0
description: Chart for cloudnative-pg cluster description: Chart for cloudnative-pg cluster
keywords: keywords:
- database - database

View File

@@ -3,20 +3,20 @@
backup: backup:
retentionPolicy: {{ .Values.backup.retentionPolicy }} retentionPolicy: {{ .Values.backup.retentionPolicy }}
barmanObjectStore: barmanObjectStore:
destinationPath: "s3://{{ .Values.backup.endpointBucket }}/{{ .Values.kubernetesClusterName }}/postgresql/{{ .Release.Name }}" destinationPath: "s3://{{ .Values.backup.endpointBucket }}/{{ .Values.kubernetesClusterName }}/postgresql/{{ include "cluster.name" . }}"
endpointURL: {{ .Values.backup.endpointURL }} endpointURL: {{ .Values.backup.endpointURL }}
{{- if .Values.backup.endpointCA }} {{- if .Values.backup.endpointCA }}
endpointCA: endpointCA:
name: {{ .Values.backup.endpointCA }} name: {{ .Values.backup.endpointCA }}
key: ca-bundle.crt key: ca-bundle.crt
{{- end }} {{- end }}
serverName: "postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.backup.backupIndex }}" serverName: "{{ include "cluster.name" . }}-backup-{{ .Values.backup.backupIndex }}"
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
name: {{ include "cluster.backup.credentials" . }} name: {{ include "cluster.backupCredentials" . }}
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
secretAccessKey: secretAccessKey:
name: {{ include "cluster.backup.credentials" . }} name: {{ include "cluster.backupCredentials" . }}
key: ACCESS_SECRET_KEY key: ACCESS_SECRET_KEY
wal: wal:
compression: {{ .Values.backup.wal.compression }} compression: {{ .Values.backup.wal.compression }}

View File

@@ -46,9 +46,9 @@ bootstrap:
{{- end }} {{- end }}
{{- end }} {{- end }}
source: source:
externalCluster: "postgresql-{{ .Release.Name }}-cluster" externalCluster: "{{ include "cluster.name" . }}-cluster"
externalClusters: externalClusters:
- name: "postgresql-{{ .Release.Name }}-cluster" - name: "{{ include "cluster.name" . }}-cluster"
{{- with .Values.replica.externalCluster }} {{- with .Values.replica.externalCluster }}
{{- . | toYaml | nindent 4 }} {{- . | toYaml | nindent 4 }}
{{- end }} {{- end }}
@@ -58,25 +58,25 @@ externalClusters:
recoveryTarget: recoveryTarget:
targetTime: {{ . }} targetTime: {{ . }}
{{- end }} {{- end }}
source: "postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.recovery.recoveryIndex }}" source: "{{ include "cluster.name" . }}-backup-{{ .Values.recovery.recoveryIndex }}"
externalClusters: externalClusters:
- name: "postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.recovery.recoveryIndex }}" - name: "{{ include "cluster.name" . }}-backup-{{ .Values.recovery.recoveryIndex }}"
barmanObjectStore: barmanObjectStore:
serverName: "postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.recovery.recoveryIndex }}" serverName: "{{ include "cluster.name" . }}-backup-{{ .Values.recovery.recoveryIndex }}"
destinationPath: "s3://{{ .Values.recovery.endpointBucket }}/{{ .Values.kubernetesClusterName }}/postgresql/{{ .Release.Name }}" destinationPath: "s3://{{ .Values.recovery.endpointBucket }}/{{ .Values.kubernetesClusterName }}/postgresql/{{ .Values.recovery.recoveryName }}"
endpointURL: {{ .Values.recovery.endpointURL }} endpointURL: {{ .Values.recovery.endpointURL }}
{{- with .Values.recovery.endpointCA }} {{- with .Values.recovery.endpointCA }}
endpointCA: endpointCA:
name: {{ . }} name: {{ . }}
key: ca-bundle.crt key: ca-bundle.crt
{{- end }} {{- end }}
serverName: "postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.recovery.recoveryIndex }}" serverName: "{{ include "cluster.name" . }}-backup-{{ .Values.recovery.recoveryIndex }}"
s3Credentials: s3Credentials:
accessKeyId: accessKeyId:
name: {{ include "cluster.recovery.credentials" . }} name: {{ include "cluster.recoveryCredentials" . }}
key: ACCESS_KEY_ID key: ACCESS_KEY_ID
secretAccessKey: secretAccessKey:
name: {{ include "cluster.recovery.credentials" . }} name: {{ include "cluster.recoveryCredentials" . }}
key: ACCESS_SECRET_KEY key: ACCESS_SECRET_KEY
wal: wal:
compression: {{ .Values.recovery.wal.compression }} compression: {{ .Values.recovery.wal.compression }}

View File

@@ -2,26 +2,13 @@
Expand the name of the chart. Expand the name of the chart.
*/}} */}}
{{- define "cluster.name" -}} {{- define "cluster.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- if .Values.nameOverride }}
{{- end }} {{- .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "cluster.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }} {{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} {{ $version := split "." .Values.cluster.image.tag }}
{{- printf "postgresql-%s-%s" $version._0 .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }}
{{/* {{/*
Create chart name and version as used by the chart label. Create chart name and version as used by the chart label.
@@ -54,18 +41,29 @@ app.kubernetes.io/part-of: cloudnative-pg
{{/* {{/*
Generate name for object store credentials Generate name for object store credentials
*/}} */}}
{{- define "cluster.recovery.credentials" -}} {{- define "cluster.recoveryCredentials" -}}
{{- if .Values.recovery.endpointCredentials -}} {{- if .Values.recovery.endpointCredentials -}}
{{- .Values.recovery.endpointCredentials -}} {{- .Values.recovery.endpointCredentials -}}
{{- else -}} {{- else -}}
{{- printf "postgresql-%s-cluster-backup-secret" .Release.Name | trunc 63 | trimSuffix "-" -}} {{- printf "postgresql-%s-cluster-backup-secret" .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end }} {{- end }}
{{- end -}} {{- end }}
{{- define "cluster.backup.credentials" -}} {{- define "cluster.backupCredentials" -}}
{{- if .Values.backup.endpointCredentials -}} {{- if .Values.backup.endpointCredentials -}}
{{- .Values.backup.endpointCredentials -}} {{- .Values.backup.endpointCredentials -}}
{{- else -}} {{- else -}}
{{- printf "postgresql-%s-cluster-backup-secret" .Release.Name | trunc 63 | trimSuffix "-" -}} {{- printf "postgresql-%s-cluster-backup-secret" .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end }} {{- end }}
{{- end -}} {{- end }}
{{/*
Generate recovery server name
*/}}
{{- define "cluster.recoveryName" -}}
{{- if .Values.recovery.recoveryName -}}
{{- .Values.recovery.recoveryName -}}
{{- else -}}
{{ include "cluster.name" . }}
{{- end }}
{{- end }}

View File

@@ -1,7 +1,7 @@
apiVersion: postgresql.cnpg.io/v1 apiVersion: postgresql.cnpg.io/v1
kind: Cluster kind: Cluster
metadata: metadata:
name: "postgresql-{{ include "cluster.fullname" . }}-cluster" name: {{ include "cluster.name" . }}-cluster
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
{{- with .Values.cluster.annotations }} {{- with .Values.cluster.annotations }}
annotations: annotations:

View File

@@ -2,7 +2,7 @@
apiVersion: monitoring.coreos.com/v1 apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule kind: PrometheusRule
metadata: metadata:
name: "postgresql-{{ include "cluster.fullname" . }}-alert-rules" name: {{ include "cluster.name" . }}-alert-rules
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
labels: labels:
{{- include "cluster.labels" . | nindent 4 }} {{- include "cluster.labels" . | nindent 4 }}
@@ -11,14 +11,14 @@ metadata:
{{- end }} {{- end }}
spec: spec:
groups: groups:
- name: cloudnative-pg/{{ include "cluster.fullname" . }} - name: cloudnative-pg/{{ include "cluster.name" . }}
rules: rules:
{{- $dict := dict "excludeRules" .Values.cluster.monitoring.prometheusRule.excludeRules -}} {{- $dict := dict "excludeRules" .Values.cluster.monitoring.prometheusRule.excludeRules -}}
{{- $_ := set $dict "value" "{{ $value }}" -}} {{- $_ := set $dict "value" "{{ $value }}" -}}
{{- $_ := set $dict "namespace" .Release.Namespace -}} {{- $_ := set $dict "namespace" .Release.Namespace -}}
{{- $_ := set $dict "cluster" (include "cluster.fullname" .) -}} {{- $_ := set $dict "cluster" (printf "%s-cluster" (include "cluster.name" .) ) -}}
{{- $_ := set $dict "labels" (dict "job" "{{ $labels.job }}" "node" "{{ $labels.node }}" "pod" "{{ $labels.pod }}") -}} {{- $_ := set $dict "labels" (dict "job" "{{ $labels.job }}" "node" "{{ $labels.node }}" "pod" "{{ $labels.pod }}") -}}
{{- $_ := set $dict "podSelector" (printf "%s-([1-9][0-9]*)$" (include "cluster.fullname" .)) -}} {{- $_ := set $dict "podSelector" (printf "%s-cluster-([1-9][0-9]*)$" (include "cluster.name" .) ) -}}
{{- $_ := set $dict "Values" .Values -}} {{- $_ := set $dict "Values" .Values -}}
{{- $_ := set $dict "Template" .Template -}} {{- $_ := set $dict "Template" .Template -}}
{{- range $path, $_ := .Files.Glob "prometheus_rules/**.yaml" }} {{- range $path, $_ := .Files.Glob "prometheus_rules/**.yaml" }}

View File

@@ -2,7 +2,7 @@
apiVersion: postgresql.cnpg.io/v1 apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup kind: ScheduledBackup
metadata: metadata:
name: "postgresql-{{ include "cluster.fullname" . }}-cluster-scheduled-backup" name: {{ include "cluster.name" . }}-scheduled-backup
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
labels: labels:
{{- include "cluster.labels" . | nindent 4 }} {{- include "cluster.labels" . | nindent 4 }}
@@ -14,5 +14,5 @@ spec:
schedule: {{ .Values.backup.schedule }} schedule: {{ .Values.backup.schedule }}
backupOwnerReference: self backupOwnerReference: self
cluster: cluster:
name: "postgresql-{{ include "cluster.fullname" . }}-cluster" name: {{ include "cluster.name" . }}-cluster
{{ end }} {{ end }}

View File

@@ -1,7 +1,5 @@
# -- Override the name of the chart # -- Override the name of the cluster
nameOverride: "" nameOverride: ""
# -- Override the full name of the chart
fullnameOverride: ""
### ###
# -- Type of the CNPG database. Available types: # -- Type of the CNPG database. Available types:
@@ -25,7 +23,7 @@ cluster:
image: image:
repository: ghcr.io/cloudnative-pg/postgresql repository: ghcr.io/cloudnative-pg/postgresql
tag: 16.2 tag: "16.2"
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
# The UID and GID of the postgres user inside the image # The UID and GID of the postgres user inside the image
@@ -112,6 +110,9 @@ recovery:
# Generate external cluster name, uses: postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.recovery.recoveryIndex }}" # Generate external cluster name, uses: postgresql-{{ .Release.Name }}-cluster-backup-index-{{ .Values.recovery.recoveryIndex }}"
recoveryIndex: 1 recoveryIndex: 1
# Name of the recovery cluster in the object store, defaults to "cluster.name"
recoveryName: ""
wal: wal:
# WAL compression method. One of `` (for no compression), `gzip`, `bzip2` or `snappy`. # WAL compression method. One of `` (for no compression), `gzip`, `bzip2` or `snappy`.
compression: snappy compression: snappy