1. Answers
  2. Kubernetes Backup with Velero and PostgreSQL

How do I use Velero with acid.zalan.do on Kubernetes?

In this guide, we will set up Velero for backups and use the acid.zalan.do PostgreSQL operator on a Kubernetes cluster. Velero provides backup and restore capabilities for Kubernetes cluster resources and persistent volumes, while acid.zalan.do is a PostgreSQL operator that simplifies running PostgreSQL clusters on Kubernetes.

Key Points

  • Velero: A tool to backup and restore Kubernetes cluster resources and persistent volumes.
  • acid.zalan.do: A PostgreSQL operator for Kubernetes that automates the deployment and management of PostgreSQL clusters.

Steps

  1. Install Velero: Deploy Velero to the Kubernetes cluster.
  2. Install acid.zalan.do: Deploy the PostgreSQL operator.
  3. Deploy PostgreSQL Cluster: Use acid.zalan.do to deploy a PostgreSQL cluster.
  4. Configure Backup: Set up Velero to backup the PostgreSQL cluster.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Deploy Velero
const veleroNamespace = new k8s.core.v1.Namespace("velero", {
    metadata: { name: "velero" },
});

const veleroServiceAccount = new k8s.core.v1.ServiceAccount("velero", {
    metadata: {
        namespace: veleroNamespace.metadata.name,
        name: "velero",
    },
});

const veleroDeployment = new k8s.apps.v1.Deployment("velero", {
    metadata: {
        namespace: veleroNamespace.metadata.name,
    },
    spec: {
        replicas: 1,
        selector: {
            matchLabels: { app: "velero" },
        },
        template: {
            metadata: {
                labels: { app: "velero" },
            },
            spec: {
                serviceAccountName: veleroServiceAccount.metadata.name,
                containers: [{
                    name: "velero",
                    image: "velero/velero:v1.7.0",
                    args: [
                        "server",
                        "--features=EnableCSI",
                    ],
                    volumeMounts: [{
                        mountPath: "/plugins",
                        name: "plugins",
                    }],
                }],
                volumes: [{
                    name: "plugins",
                    emptyDir: {},
                }],
            },
        },
    },
});

// Deploy acid.zalan.do PostgreSQL Operator
const zalandoNamespace = new k8s.core.v1.Namespace("zalando", {
    metadata: { name: "zalando" },
});

const zalandoOperator = new k8s.helm.v3.Chart("postgres-operator", {
    namespace: zalandoNamespace.metadata.name,
    chart: "postgres-operator",
    fetchOpts: {
        repo: "https://opensource.zalando.com/postgres-operator/charts/postgres-operator",
    },
});

// Deploy PostgreSQL Cluster
const pgCluster = new k8s.apiextensions.CustomResource("pg-cluster", {
    apiVersion: "acid.zalan.do/v1",
    kind: "postgresql",
    metadata: {
        namespace: zalandoNamespace.metadata.name,
        name: "acid-minimal-cluster",
    },
    spec: {
        teamId: "acid",
        volume: {
            size: "1Gi",
        },
        numberOfInstances: 2,
        users: {
            "zalando": ["superuser", "createdb"],
        },
        databases: {
            "foo": "zalando",
        },
        postgresql: {
            version: "13",
        },
    },
});

// Configure Velero Backup
const backupSchedule = new k8s.apiextensions.CustomResource("backup-schedule", {
    apiVersion: "velero.io/v1",
    kind: "Schedule",
    metadata: {
        namespace: veleroNamespace.metadata.name,
        name: "daily-backup",
    },
    spec: {
        schedule: "0 2 * * *",
        template: {
            includedNamespaces: [zalandoNamespace.metadata.name],
            ttl: "72h",
        },
    },
});

Summary

In this guide, we deployed Velero for backups and the acid.zalan.do PostgreSQL operator on a Kubernetes cluster. We then set up a PostgreSQL cluster and configured Velero to back it up on a daily schedule. This setup ensures that your PostgreSQL data is regularly backed up and can be restored in case of any failure.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up