Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

helmchart v1.0.0

Alexander Gazalde11ab8d8ab9
diff --git a/postgresus/.helmignore b/postgresus/.helmignore
new file mode 100644
index 00000000..0e8a0eb3
--- /dev/null
+++ b/postgresus/.helmignore
@@ -0,0 +1,23 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/postgresus/Chart.yaml b/postgresus/Chart.yaml
new file mode 100644
index 00000000..5f7320a0
--- /dev/null
+++ b/postgresus/Chart.yaml
@@ -0,0 +1,15 @@
+apiVersion: v2
+name: postgresus
+description: A Helm chart for Postgresus - PostgreSQL backup and management system
+type: application
+version: 1.0.0
+appVersion: "v1.45.3"
+keywords:
+ - postgresql
+ - backup
+ - database
+ - restore
+home: https://github.com/RostislavDugin/postgresus
+maintainers:
+ - name: Alexander Gazal
diff --git a/postgresus/README.md b/postgresus/README.md
new file mode 100644
index 00000000..30341010
--- /dev/null
+++ b/postgresus/README.md
@@ -0,0 +1,189 @@
+# Postgresus Helm Chart
+
+Helm chart for deploying Postgresus - a PostgreSQL backup and management system.
+
+## Description
+
+This Helm chart deploys Postgresus in a Kubernetes cluster using StatefulSet to ensure persistent data storage.
+
+## Installation
+
+### Install with Default Values
+
+```bash
+helm install postgresus ./helm-chart/postgresus -n postgresus --create-namespace
+```
+
+### Install with Custom Values
+
+```bash
+helm install postgresus ./helm-chart/postgresus -n postgresus --create-namespace -f custom-values.yaml
+```
+
+### Upgrade Release
+
+```bash
+helm upgrade postgresus ./helm-chart/postgresus -n postgresus
+```
+
+### Uninstall Release
+
+```bash
+helm uninstall postgresus -n postgresus
+```
+
+## Configuration
+
+### Main Parameters
+
+| Parameter | Description | Default Value |
+|----------|----------|----------------------|
+| `namespace.create` | Create namespace | `true` |
+| `namespace.name` | Namespace name | `postgresus` |
+| `image.repository` | Docker image | `rostislavdugin/postgresus` |
+| `image.tag` | Image tag | `v1.34.0` |
+| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
+| `replicaCount` | Number of replicas | `1` |
+
+### Resources
+
+| Parameter | Description | Default Value |
+|----------|----------|----------------------|
+| `resources.requests.memory` | Memory request | `512Mi` |
+| `resources.requests.cpu` | CPU request | `250m` |
+| `resources.limits.memory` | Memory limit | `1Gi` |
+| `resources.limits.cpu` | CPU limit | `500m` |
+
+### Storage
+
+| Parameter | Description | Default Value |
+|----------|----------|----------------------|
+| `persistence.enabled` | Enable persistent storage | `true` |
+| `persistence.storageClassName` | Storage class | `longhorn` |
+| `persistence.accessMode` | Access mode | `ReadWriteOnce` |
+| `persistence.size` | Storage size | `10Gi` |
+| `persistence.mountPath` | Mount path | `/postgresus-data` |
+
+### Service
+
+| Parameter | Description | Default Value |
+|----------|----------|----------------------|
+| `service.type` | Service type | `ClusterIP` |
+| `service.port` | Service port | `4005` |
+| `service.targetPort` | Target port | `4005` |
+| `service.headless.enabled` | Enable headless service | `true` |
+
+### Ingress
+
+| Parameter | Description | Default Value |
+|----------|----------|----------------------|
+| `ingress.enabled` | Enable Ingress | `true` |
+| `ingress.className` | Ingress class | `nginx` |
+| `ingress.hosts[0].host` | Hostname | `postgresus.home.fwz.ru` |
+| `ingress.tls` | TLS configuration | See values.yaml |
+
+### Health Checks
+
+| Parameter | Description | Default Value |
+|----------|----------|----------------------|
+| `livenessProbe.enabled` | Enable liveness probe | `false` |
+| `readinessProbe.enabled` | Enable readiness probe | `false` |
+
+## Usage Examples
+
+### Change Image Version
+
+```yaml
+# custom-values.yaml
+image:
+ tag: v1.20.0
+```
+
+```bash
+helm upgrade postgresus ./helm-chart/postgresus -n postgresus -f custom-values.yaml
+```
+
+### Change Storage Size
+
+```yaml
+# custom-values.yaml
+persistence:
+ size: 50Gi
+```
+
+### Configure Ingress for Different Domain
+
+```yaml
+# custom-values.yaml
+ingress:
+ hosts:
+ - host: backup.example.com
+ paths:
+ - path: /
+ pathType: Prefix
+ tls:
+ - secretName: backup-example-com-tls
+ hosts:
+ - backup.example.com
+```
+
+### Enable Health Checks
+
+```yaml
+# custom-values.yaml
+livenessProbe:
+ enabled: true
+
+readinessProbe:
+ enabled: true
+```
+
+## Verify Deployment
+
+```bash
+# Check release status
+helm status postgresus -n postgresus
+
+# View pods
+kubectl get pods -n postgresus
+
+# View services
+kubectl get svc -n postgresus
+
+# View ingress
+kubectl get ingress -n postgresus
+
+# View PVC
+kubectl get pvc -n postgresus
+```
+
+## Debugging
+
+```bash
+# View logs
+kubectl logs -n postgresus -l app=postgresus
+
+# View events
+kubectl get events -n postgresus
+
+# Describe StatefulSet
+kubectl describe statefulset postgresus -n postgresus
+
+# Render templates without installation
+helm template postgresus ./helm-chart/postgresus -n postgresus
+```
+
+## Requirements
+
+- Kubernetes 1.19+
+- Helm 3.0+
+- PV provisioner (e.g., Longhorn)
+- Nginx Ingress Controller (optional)
+- Cert-Manager (optional, for automatic certificates)
+
+## Notes
+
+- The chart uses StatefulSet to ensure stable data storage
+- Headless service is created automatically for StatefulSet
+- By default, one application instance is created (replica=1)
+- It's recommended to configure a backup policy for PVC
diff --git a/postgresus/templates/_helpers.tpl b/postgresus/templates/_helpers.tpl
new file mode 100644
index 00000000..6502d49b
--- /dev/null
+++ b/postgresus/templates/_helpers.tpl
@@ -0,0 +1,72 @@
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "postgresus.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+*/}}
+{{- define "postgresus.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 }}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "postgresus.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "postgresus.labels" -}}
+helm.sh/chart: {{ include "postgresus.chart" . }}
+{{ include "postgresus.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "postgresus.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "postgresus.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+app: postgresus
+{{- end }}
+
+{{/*
+Create the name of the service account to use
+*/}}
+{{- define "postgresus.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create }}
+{{- default (include "postgresus.fullname" .) .Values.serviceAccount.name }}
+{{- else }}
+{{- default "default" .Values.serviceAccount.name }}
+{{- end }}
+{{- end }}
+
+{{/*
+Namespace
+*/}}
+{{- define "postgresus.namespace" -}}
+{{- if .Values.namespace.create }}
+{{- .Values.namespace.name }}
+{{- else }}
+{{- .Release.Namespace }}
+{{- end }}
+{{- end }}
diff --git a/postgresus/templates/ingress.yaml b/postgresus/templates/ingress.yaml
new file mode 100644
index 00000000..8d22b19b
--- /dev/null
+++ b/postgresus/templates/ingress.yaml
@@ -0,0 +1,42 @@
+{{- if .Values.ingress.enabled -}}
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ name: {{ include "postgresus.fullname" . }}-ingress
+ namespace: {{ include "postgresus.namespace" . }}
+ labels:
+ {{- include "postgresus.labels" . | nindent 4 }}
+ {{- with .Values.ingress.annotations }}
+ annotations:
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+spec:
+ {{- if .Values.ingress.className }}
+ ingressClassName: {{ .Values.ingress.className }}
+ {{- end }}
+ {{- if .Values.ingress.tls }}
+ tls:
+ {{- range .Values.ingress.tls }}
+ - hosts:
+ {{- range .hosts }}
+ - {{ . | quote }}
+ {{- end }}
+ secretName: {{ .secretName }}
+ {{- end }}
+ {{- end }}
+ rules:
+ {{- range .Values.ingress.hosts }}
+ - host: {{ .host | quote }}
+ http:
+ paths:
+ {{- range .paths }}
+ - path: {{ .path }}
+ pathType: {{ .pathType }}
+ backend:
+ service:
+ name: {{ include "postgresus.fullname" $ }}-service
+ port:
+ number: {{ $.Values.service.port }}
+ {{- end }}
+ {{- end }}
+{{- end }}
diff --git a/postgresus/templates/namespace.yaml b/postgresus/templates/namespace.yaml
new file mode 100644
index 00000000..73771281
--- /dev/null
+++ b/postgresus/templates/namespace.yaml
@@ -0,0 +1,8 @@
+{{- if .Values.namespace.create }}
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: {{ .Values.namespace.name }}
+ labels:
+ {{- include "postgresus.labels" . | nindent 4 }}
+{{- end }}
diff --git a/postgresus/templates/service.yaml b/postgresus/templates/service.yaml
new file mode 100644
index 00000000..f252b046
--- /dev/null
+++ b/postgresus/templates/service.yaml
@@ -0,0 +1,36 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ include "postgresus.fullname" . }}-service
+ namespace: {{ include "postgresus.namespace" . }}
+ labels:
+ {{- include "postgresus.labels" . | nindent 4 }}
+spec:
+ type: {{ .Values.service.type }}
+ ports:
+ - port: {{ .Values.service.port }}
+ targetPort: {{ .Values.service.targetPort }}
+ protocol: TCP
+ name: http
+ selector:
+ {{- include "postgresus.selectorLabels" . | nindent 4 }}
+---
+{{- if .Values.service.headless.enabled }}
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ include "postgresus.fullname" . }}-headless
+ namespace: {{ include "postgresus.namespace" . }}
+ labels:
+ {{- include "postgresus.labels" . | nindent 4 }}
+spec:
+ type: ClusterIP
+ clusterIP: None
+ ports:
+ - port: {{ .Values.service.port }}
+ targetPort: {{ .Values.service.targetPort }}
+ protocol: TCP
+ name: http
+ selector:
+ {{- include "postgresus.selectorLabels" . | nindent 4 }}
+{{- end }}
diff --git a/postgresus/templates/statefulset.yaml b/postgresus/templates/statefulset.yaml
new file mode 100644
index 00000000..5281d45d
--- /dev/null
+++ b/postgresus/templates/statefulset.yaml
@@ -0,0 +1,80 @@
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+ name: {{ include "postgresus.fullname" . }}
+ namespace: {{ include "postgresus.namespace" . }}
+ labels:
+ {{- include "postgresus.labels" . | nindent 4 }}
+spec:
+ serviceName: {{ include "postgresus.fullname" . }}-headless
+ replicas: {{ .Values.replicaCount }}
+ selector:
+ matchLabels:
+ {{- include "postgresus.selectorLabels" . | nindent 6 }}
+ template:
+ metadata:
+ annotations:
+ {{- with .Values.podAnnotations }}
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ labels:
+ {{- include "postgresus.selectorLabels" . | nindent 8 }}
+ {{- with .Values.podLabels }}
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ spec:
+ {{- with .Values.nodeSelector }}
+ nodeSelector:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ {{- with .Values.affinity }}
+ affinity:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ {{- with .Values.tolerations }}
+ tolerations:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ containers:
+ - name: {{ .Chart.Name }}
+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+ imagePullPolicy: {{ .Values.image.pullPolicy }}
+ ports:
+ - name: http
+ containerPort: {{ .Values.service.targetPort }}
+ protocol: TCP
+ volumeMounts:
+ - name: postgresus-storage
+ mountPath: {{ .Values.persistence.mountPath }}
+ resources:
+ {{- toYaml .Values.resources | nindent 12 }}
+ {{- if .Values.livenessProbe.enabled }}
+ livenessProbe:
+ {{- toYaml .Values.livenessProbe.httpGet | nindent 12 }}
+ initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
+ periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
+ timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
+ failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
+ {{- end }}
+ {{- if .Values.readinessProbe.enabled }}
+ readinessProbe:
+ {{- toYaml .Values.readinessProbe.httpGet | nindent 12 }}
+ initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
+ periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
+ timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
+ failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
+ {{- end }}
+ {{- if .Values.persistence.enabled }}
+ volumeClaimTemplates:
+ - metadata:
+ name: postgresus-storage
+ spec:
+ accessModes:
+ - {{ .Values.persistence.accessMode }}
+ storageClassName: {{ .Values.persistence.storageClassName }}
+ resources:
+ requests:
+ storage: {{ .Values.persistence.size }}
+ {{- end }}
+ updateStrategy:
+ {{- toYaml .Values.updateStrategy | nindent 4 }}
diff --git a/postgresus/values.yaml b/postgresus/values.yaml
new file mode 100644
index 00000000..d4358f75
--- /dev/null
+++ b/postgresus/values.yaml
@@ -0,0 +1,108 @@
+# Default values for postgresus
+
+# Namespace configuration
+namespace:
+ create: true
+ name: postgresus
+
+# Image configuration
+image:
+ repository: rostislavdugin/postgresus
+ tag: v1.45.3
+ pullPolicy: IfNotPresent
+
+# StatefulSet configuration
+replicaCount: 1
+
+# Service configuration
+service:
+ type: ClusterIP
+ port: 4005
+ targetPort: 4005
+ # Headless service for StatefulSet
+ headless:
+ enabled: true
+
+# Resource limits and requests
+resources:
+ requests:
+ memory: "512Mi"
+ cpu: "250m"
+ limits:
+ memory: "1Gi"
+ cpu: "500m"
+
+# Persistent storage configuration
+persistence:
+ enabled: true
+ storageClassName: longhorn-pg
+ accessMode: ReadWriteOnce
+ size: 10Gi
+ # Mount path in container
+ mountPath: /postgresus-data
+
+# Ingress configuration
+ingress:
+ enabled: true
+ className: nginx
+ annotations:
+ nginx.ingress.kubernetes.io/rewrite-target: /
+ nginx.ingress.kubernetes.io/ssl-redirect: "true"
+ nginx.ingress.kubernetes.io/use-http2: "true"
+ # Gzip settings
+ nginx.ingress.kubernetes.io/enable-gzip: "true"
+ nginx.ingress.kubernetes.io/gzip-types: "text/plain text/css application/json application/javascript text/javascript text/xml application/xml application/xml+rss image/svg+xml"
+ nginx.ingress.kubernetes.io/gzip-min-length: "1000"
+ nginx.ingress.kubernetes.io/gzip-level: "9"
+ nginx.ingress.kubernetes.io/gzip-buffers: "16 8k"
+ nginx.ingress.kubernetes.io/gzip-http-version: "1.1"
+ nginx.ingress.kubernetes.io/gzip-vary: "on"
+ # Cert-manager settings
+ cert-manager.io/cluster-issuer: "clusteriissuer-letsencrypt"
+ cert-manager.io/duration: "2160h"
+ cert-manager.io/renew-before: "360h"
+ hosts:
+ - host: postgresus.example.com
+ paths:
+ - path: /
+ pathType: Prefix
+ tls:
+ - secretName: postgresus.example.com-tls
+ hosts:
+ - postgresus.example.com
+
+# Health checks configuration (commented out by default)
+livenessProbe:
+ enabled: false
+ httpGet:
+ path: /health
+ port: 4005
+ initialDelaySeconds: 30
+ periodSeconds: 10
+ timeoutSeconds: 5
+ failureThreshold: 3
+
+readinessProbe:
+ enabled: false
+ httpGet:
+ path: /ready
+ port: 4005
+ initialDelaySeconds: 5
+ periodSeconds: 5
+ timeoutSeconds: 3
+ failureThreshold: 3
+
+# StatefulSet update strategy
+updateStrategy:
+ type: RollingUpdate
+ rollingUpdate:
+ partition: 0
+
+# Pod labels and annotations
+podLabels: {}
+podAnnotations: {}
+
+# Node selector, tolerations and affinity
+nodeSelector: {}
+tolerations: []
+affinity: {}