<p>I have used this <a href="https://severalnines.com/database-blog/using-kubernetes-deploy-postgresql" rel="nofollow noreferrer">link</a> to deploy Postgres on Kubernetes.</p>

<p>below is the configmap :</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  labels:
    app: postgres
data:
  POSTGRES_DB: postgresdb
  POSTGRES_USER: postgresadmin
  POSTGRES_PASSWORD: admin123
</code></pre>

<p>and deployment :</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:10.4
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:
                name: postgres-config
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pv-claim
</code></pre>

<p>I hope, a simple configuration at configmap or deployment yaml will help to create a new schema on postgres db.</p>

Siddhanta Rath
<p>You can use Kubernetes postStart lifecycle hook to create your schema on given Postgres DB. Just update your deployment file with the lifecycle block.</p>

<pre><code>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 &amp;&amp; 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: {}
</code></pre>
