Red Hat
developers.redhat.com › learning › learn:openshift:build-and-populate-database-using-kubernetes-init-containers › resource › resources:create-postgresql-instance-configmap-and-deployment-objects
Create the PostgreSQL instance, ConfigMap, and Deployment objects | Build and populate a database using Kubernetes init containers | Red Hat Developer
February 17, 2026 - Likewise, you can view the Kubernetes documentation related to configuring a pod to use a ConfigMap. When those two pieces of knowledge are combined, you get a deployment that, in our case, includes the following (an explanation follows this section of the YAML file): spec: initContainers: - name: init-createdb image: postgres:14 command: ["psql", "postgresql://postgres:postgres@postgresql", "-f", "/etc/rsalbums/create_database.sql"] volumeMounts: - name: albums-volume mountPath: /etc/rsalbums - name: init-builddb image: postgres:14 command: ["psql", "postgresql://postgres:postgres@postgresql/
Stack Overflow
stackoverflow.com › questions › 64259293 › change-postgres-config-using-kubernetes-configmap
postgresql - Change Postgres config using Kubernetes configMap - Stack Overflow
October 8, 2020 - apiVersion: v1 kind: ConfigMap metadata: name: pg-hba-configmap data: pg_hba.conf: |+ # TYPE DATABASE USER ADDRESS METHOD # Some personal settings here --- apiVersion: apps/v1 kind: StatefulSet metadata: name: db spec: selector: matchLabels: app: db serviceName: db replicas: 1 template: metadata: labels: app: db spec: nodeSelector: db: 'true' containers: - name: db image: kartoza/postgis:10.0-2.4 volumeMounts: - name: data-volume mountPath: /var/lib/postgresql - name: pg-hba-config-volume mountPath: /var/lib/postgresql/10/main/pg_hba.conf subPath: pg_hba.conf volumes: - name: data-volume hostPath: path: /data/db - name: pg-hba-config-volume configMap: name: pg-hba-configmap
DigitalOcean
digitalocean.com › community › tutorials › how-to-deploy-postgres-to-kubernetes-cluster
How to Deploy Postgres to Kubernetes Cluster | DigitalOcean
March 25, 2026 - kubectl create secret generic postgres-auth \ --namespace postgres-demo \ --from-literal=POSTGRES_PASSWORD='ReplaceWithStrongPassword' ... apiVersion: v1 kind: ConfigMap metadata: name: postgres-config namespace: postgres-demo data: POSTGRES_DB: appdb POSTGRES_USER: appuser
GitHub
github.com › kubernetes › kubernetes › issues › 70241
config map vs secret to store credentials for Postgres deployment · Issue #70241 · kubernetes/kubernetes
October 25, 2018 - - env: - name: POSTGRES_DB valueFrom: configMapKeyRef: name: postgres-config key: POSTGRES_DB - name: POSTGRES_USER valueFrom: configMapKeyRef: name: postgres-config key: POSTGRES_USER - name: POSTGRES_PASSWORD valueFrom: configMapKeyRef: name: postgres-config key: POSTGRES_PASSWORD
Author AndriiOmelianenko
Kubegres
kubegres.io › doc › override-default-configs.html
Override default configs
This script above assumes that the env-var $POSTGRES_MY_DB_PASSWORD contains the password of the custom user to create. Please see an example about how to add a custom env-variable. Please see below an example of an overridden "backup_database.sh" in a custom ConfigMap, which contains the logic to dump PostgreSql Primary's database:
Medium
medium.com › @xcoulon › managing-pod-configuration-using-configmaps-and-secrets-in-kubernetes-93a2de9449be
Managing Pod configuration using ConfigMaps and Secrets in Kubernetes | by Xavier Coulon | Medium
November 28, 2017 - $ kubectl create -f templates/database-deployment.yml deployment "postgres" created$ kubectl get all NAME READY STATUS RESTARTS AGE po/postgres-3585693371-xnzjv 1/1 Running 0 5sNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/postgres 10.0.0.191 <none> 5432/TCP 7dNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/postgres 1 1 1 1 5sNAME DESIRED CURRENT READY AGE rs/postgres-3585693371 1 1 1 5s
Eksworkshop
developers.eksworkshop.com › introduction to kubernetes › initializing postgresql database with kubernetes configmaps
Initializing PostgreSQL Database with Kubernetes ConfigMaps | EKS Developers Workshop
This lab walks you through the process of creating a Kubernetes ConfigMap for the init.sh script in the 'my-cool-app' namespace. ... Navigate to the root directory of the python-fastapi-demo-docker project where your environment variables are sourced: ... Our PostgreSQL database requires custom ...
BMC Software
bmc.com › blogs › kubernetes-postgresql
Deploying PostgreSQL as a StatefulSet in Kubernetes – BMC Software | Blogs
July 2, 2021 - This will also enable us to create a StatefulSet using the data in the ConfigMap. # PostgreSQL StatefulSet - ConfigMap apiVersion: apps/v1 kind: StatefulSet metadata: name: postgresql-db spec: serviceName: postgresql-db-service selector: matchLabels: app: postgresql-db replicas: 2 template: metadata: labels: app: postgresql-db spec: containers: - name: postgresql-db image: postgres:latest volumeMounts: - name: postgresql-db-disk mountPath: /data # Config from ConfigMap envFrom: - configMapRef: name: postgres-db-config # Volume Claim volumeClaimTemplates: - metadata: name: postgresql-db-disk spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 25Gi
GitHub
github.com › zalando › postgres-operator › blob › master › manifests › configmap.yaml
postgres-operator/manifests/configmap.yaml at master · zalando/postgres-operator
pdb_name_format: "postgres-{cluster}-pdb" persistent_volume_claim_retention_policy: "when_deleted:retain,when_scaled:retain" pod_antiaffinity_preferred_during_scheduling: "false" pod_antiaffinity_topology_key: "kubernetes.io/hostname" pod_deletion_wait_timeout: 10m · # pod_environment_configmap: "default/my-custom-config" # pod_environment_secret: "my-custom-secret" pod_label_wait_timeout: 10m ·
Author zalando
Readthedocs
postgres-operator.readthedocs.io › en › stable › reference › operator_parameters
Configuration parameters - Postgres Operator - Read the Docs
In that case, the operator defines a pod toleration according to the values of those keys. See kubernetes documentation for details on taints and tolerations. The default is empty. pod_environment_configmap namespaced name of the ConfigMap with environment variables to populate on every pod.
VMware
techdocs.broadcom.com › us › en › vmware-tanzu › data-solutions › tanzu-for-postgres-on-kubernetes › 3-0 › tnz-postgres-k8s › configure-postgresql-server.html
Customizing the PostgreSQL Server - Broadcom TechDocs
January 23, 2026 - apiVersion: v1 kind: ConfigMap metadata: name: my-postgresql-configmap labels: app: postgres data: log_truncate_on_rotation: "on" log_rotation_age: "1d" log_filename: "postgresql-%A.log" log_rotation_size: "0" logging_collector: "on" Once Kubernetes updates the volume mount, it applies your changes, and the pods will be restarted based on the parameter Restart field value:
Medium
jineshnagori.medium.com › ultimate-guide-to-setting-up-postgresql-in-kubernetes-with-statefulsets-adminer-dashboard-and-6232323cb4dc
Ultimate Guide to Setting Up PostgreSQL in Kubernetes with StatefulSets, Adminer Dashboard, and Ingress. | by Jinesh Nagori | Medium
August 29, 2023 - kind: PersistentVolume apiVersion: v1 metadata: name: postgres-pv-volume labels: type: local app: postgres spec: storageClassName: manual capacity: storage: 5Gi accessModes: - ReadWriteMany hostPath: path: "/mnt/data" A ConfigMaps in Kubernetes lets us mount files on containers without the need to make changes to the Dockerfile or rebuilding the container image.
VMware
techdocs.broadcom.com › us › en › vmware-tanzu › data-solutions › tanzu-for-postgres-on-kubernetes › 3-0 › tnz-postgres-k8s › configure-pghba-file.html
Configure the pg_hba.conf File - Broadcom TechDocs
January 23, 2026 - apiVersion: v1 kind: ConfigMap metadata: name: my-postgresql-hba-configmap labels: app: postgres data: pg_hba.custom.conf: | host "postgres-sample" "pgappuser" ::0/0 scram-sha-256 host "postgres-sample" "pgadmin" ::0/0 scram-sha-256 ... After Kubernetes updates the volume mount it applies your changes, and the Postgres server is reloaded to include your changes:
Top answer 1 of 3
5
You can use Kubernetes postStart lifecycle hook to create your schema on given Postgres DB. Just update your deployment file with the lifecycle block.
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: postgres
name: postgres
spec:
containers:
- image: postgres:10.4
name: postgres
resources: {}
lifecycle:
postStart:
exec:
command: ["/bin/bash","-c","sleep 20 && PGPASSWORD=$POSTGRES_PASSWORD psql $POSTGRES_DB -U $POSTGRES_USER -c \'CREATE SCHEMA IF NOT EXISTS key;\'"]
envFrom:
- configMapRef:
name: postgres-config
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: data
dnsPolicy: ClusterFirst
restartPolicy: Never
volumes:
- name: data
emptyDir: {}
status: {}
2 of 3
3
For your use-case, it is better to setup PostgreSQL using Helm charts, for e.g.:
helm install stable/postgresql \
--set global.postgresql.postgresqlDatabase=postgresdb \
--set global.postgresql.postgresqlUsername=postgresadmin \
--set global.postgresql.postgresqlPassword=admin123 \
--set global.postgresql.servicePort=5432 \
--set initdbScripts."init\.sql"="CREATE SCHEMA IF NOT EXISTS key;"