KubeKanvas Logo
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
Back to Templates

Deploy Postgresql in Kubernetes with backup

Tags:
PostgresqlStatefulsetPostgresql with backup
Created by:
Mahmood
Deploy Postgresql in Kubernetes with backup  template preview
1 uses
KubeKanvas Logo
Visual Kubernetes cluster design tool that helps you create, manage, and deploy your applications with ease.
Product
  • Features
  • Pricing
  • Templates
Resources
  • Blog
  • Tutorials
Company
  • About Us
  • Contact
  • Terms of Service
  • Privacy Policy
  • Impressum
XGitHubLinkedIn
© 2026 KubeKanvas. All rights reserved.

Deploying PostgreSQL as a standard Kubernetes Deployment does not guarantee stable pod identity or reliable storage reattachment after restarts. This template deploys PostgreSQL 15 as a StatefulSet with a PersistentVolumeClaim, a headless Service for stable DNS, externalized credentials, a readiness probe, and a scheduled backup CronJob, giving you a production-grade PostgreSQL deployment on Kubernetes that maintains data integrity across pod restarts.

What's Included

ComponentTypePortRole
PostgreSQL 15StatefulSet5432Primary database with stable pod identity and persistent storage
PersistentVolumeClaimPersistentVolumeClaim-ReadWriteOnce data volume that reattaches after pod restarts
Headless ServiceService-Stable DNS resolution for direct pod addressing
ConfigMapConfigMap-Database name and user configuration
SecretSecret-Password injected as environment variable at runtime
Backup CronJobCronJob-Scheduled database backups

Architecture Overview

PostgreSQL 15 runs as a StatefulSet so each pod gets a stable name (postgres-0) and DNS address via the headless Service (postgres-0.postgres-headless). A PVC with ReadWriteOnce access mode binds to the pod and reattaches automatically after restarts. The ConfigMap holds the database name and user, while a Kubernetes Secret injects the password at runtime. A readiness probe using pg_isready gates traffic until the database is ready to accept connections. A CronJob handles scheduled backups.

Prerequisites

  • A running Kubernetes cluster
  • Storage class configured for dynamic PVC provisioning
  • KubeKanvas CLI installed and running on your computer (Optional, if you want to use one-click deployment)

How to Deploy

  1. Click on the button at the top right corner of this page to load the manifest into the editor.
  2. Update the ConfigMap with your database name and username.
  3. Replace the password placeholder in the Secret with your base64-encoded PostgreSQL password.
  4. Confirm the storage class in the PVC definition matches what is available in your cluster.
  5. Deploy the template to your cluster via the Play button in the top right bar. If you prefer to deploy manually, download the YAML and apply it with kubectl.
  6. Wait for all pods to reach Running status. You can monitor progress in the Release Monitor screen.

How to Test

  1. Confirm the StatefulSet pod is running and the PVC is bound: kubectl get pods,pvc -n <namespace>.
  2. Open a shell on the pod: kubectl exec -it postgres-0 -n <namespace> -- psql -U <username> -d <dbname>.
  3. Run \l to list databases and verify your configured database exists.
  4. Run SELECT version(); to confirm PostgreSQL 15 is running.

Use Cases

  • Stateful database workloads: Replacing a PostgreSQL Deployment with a StatefulSet to guarantee stable pod identity and persistent storage across restarts.
  • Backup-enabled database setup: Running PostgreSQL on Kubernetes with scheduled CronJob backups without additional external tooling.
  • Direct pod addressing: Applications that need to connect to a specific PostgreSQL pod by DNS using the headless Service endpoint.
  • Credential-isolated configuration: Projects that require the database password stored in a Kubernetes Secret rather than hardcoded in manifests.

Summary

This template configures a PostgreSQL 15 StatefulSet on Kubernetes with persistent storage, stable DNS via a headless Service, externalized credentials, and scheduled backups.