<p>What's the best approach for backing up a Postgres on Kubernetes?</p>
<p>My first guess would have been to create a master-slave architecture with enabling replication. Doing an initial pg_basebackup and then fetching the WAL-logs. Once in a month I'd have scheduled another pg_basebackup with a cron, however containerized environemnts don't like cron daemons (no systemd available). How do you schedule base backups?</p>

<p>The best approach is to use the Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="noreferrer">Cronjob</a> resource:</p>
<blockquote>
<p>You can use a CronJob to run <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="noreferrer">Jobs</a> on a time-based schedule. These
automated jobs run like Cron tasks on a Linux or UNIX system.</p>
<p>Cron jobs are useful for creating periodic and recurring tasks, like
running backups or sending emails.</p>
</blockquote>
<p>You basically need to create a custom Linux image to run in your container jobs. This image will need a Postgres Client (so you can connect to your database with <code>psql</code>, <code>pg_dump</code> or <code>pg_basebackup</code>); and the credentials that can be configured as a <a href="https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/" rel="noreferrer">secret</a>.</p>
<p>You may want to upload the backup to external storage, so you can install and use <code>awscli</code> for AWS S3, <code>gsutil</code> for Google Cloud Storage, etc...</p>
<p>Here is some references:</p>
<ul>
<li><a href="https://devtron.ai/blog/creating-a-kubernetes-cron-job-to-backup-postgres-db/" rel="noreferrer">Creating a Kubernetes Cron Job to backup Postgres DB</a></li>
<li><a href="https://cwienczek.com/2020/06/simple-backup-of-postgres-database-in-kubernetes/" rel="noreferrer">Simple backup of postgres database in kubernetes</a></li>
<li><a href="https://www.orange-networks.com/blogs/208-back-up-databases-using-kubernetes-cronjobs" rel="noreferrer">Back up databases using Kubernetes CronJobs</a></li>
</ul>
