1. Answers
  2. Managing custom Postgres configurations with ConfigMaps in Kubegres

How Do I Manage Custom Postgres Configurations With ConfigMaps in Kubegres?

In this guide, we will manage custom Postgres configurations using ConfigMaps in a Kubegres deployment with Pulumi. ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. We will create a ConfigMap to store custom Postgres configuration and then apply it to our Kubegres Postgres deployment.

Key Points:

  • Create a ConfigMap with custom Postgres configuration.
  • Deploy a Kubegres Postgres cluster using the custom configuration.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Create a ConfigMap with custom Postgres configuration
const postgresConfigMap = new k8s.core.v1.ConfigMap("postgres-config", {
    metadata: { name: "postgres-config" },
    data: {
        "postgresql.conf": `
            max_connections = 100
            shared_buffers = 128MB
            effective_cache_size = 256MB
            maintenance_work_mem = 64MB
            checkpoint_completion_target = 0.7
        `,
    },
});

// Deploy a Kubegres Postgres cluster using the custom configuration
const kubegres = new k8s.apiextensions.CustomResource("kubegres-postgres", {
    apiVersion: "kubegres.reactive-tech.io/v1",
    kind: "Kubegres",
    metadata: {
        name: "my-postgres",
    },
    spec: {
        replicas: 1,
        image: "postgres:13.3",
        database: {
            size: "1Gi",
        },
        env: [
            {
                name: "PGDATA",
                value: "/var/lib/postgresql/data/pgdata",
            },
        ],
        volumeMounts: [
            {
                name: "config-volume",
                mountPath: "/var/lib/postgresql/data/pgdata/postgresql.conf",
                subPath: "postgresql.conf",
            },
        ],
        volumes: [
            {
                name: "config-volume",
                configMap: {
                    name: postgresConfigMap.metadata.name,
                },
            },
        ],
    },
});

export const configMapName = postgresConfigMap.metadata.name;
export const kubegresName = kubegres.metadata.name;

Summary

In this guide, we created a ConfigMap to store custom Postgres configurations and deployed a Kubegres Postgres cluster using that configuration. This allows for easy management and updates to Postgres settings without modifying the container image.

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