<p>In a multi-container pod:</p>
<p>step-1: Deploy first container Postgres Database and create a schema</p>
<p>step-2: Wait until the Postgres pod came up</p>
<p>step-3: then start deploying second container keycloak</p>
<p>I have written below deployment file to run :</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: idms
  namespace: default
  labels:
    app: idms
spec:
  replicas: 1
  selector:
    matchLabels:
      app: idms
  template:
    metadata:
      labels:
        app: idms
    spec:
      containers:
       - name: postgres
         image: registry.prod.srv.da.nsn-rdnet.net/edge/postgres:12.3-alpine
         imagePullPolicy: &quot;IfNotPresent&quot;
         ports:
           - containerPort: 5432
         lifecycle:
            postStart:
              exec:
                command: [&quot;/bin/bash&quot;,&quot;-c&quot;,&quot;sleep 5 &amp;&amp; PGPASSWORD=$POSTGRES_PASSWORD psql $POSTGRES_DB -U $POSTGRES_USER -c \'CREATE SCHEMA IF NOT EXISTS keycloak;\'&quot;]  
         envFrom:
           - configMapRef:
               name: postgres-config
       - name: keycloak
         image: quay.io/keycloak/keycloak:10.0.1
         env:
          - name: KEYCLOAK_USER
            value: &quot;admin&quot;
          - name: KEYCLOAK_PASSWORD
            value: &quot;admin&quot;
          - name: REALM
            value: &quot;ntc&quot;
          - name: PROXY_ADDRESS_FORWARDING
            value: &quot;true&quot;
          - name: DB_ADDR
            value: &quot;localhost&quot;
          - name: DB_PORT
            value: &quot;5432&quot;
          - name: DB_DATABASE
            value: &quot;postgresdb&quot;
          - name: DB_USER
            value: &quot;xxxxxxxxx&quot;
          - name: DB_PASSWORD
            value: &quot;xxxxxxxxx&quot;
          - name: DB_SCHEMA
            value: &quot;keycloak&quot;    
          - name: KEYCLOAK_IMPORT
            value: &quot;/opt/jboss/keycloak/startup/elements/realm.json&quot;
         volumeMounts:
           - mountPath: /var/lib/postgresql/data
             name: postgredb 
           - mountPath: /opt/jboss/keycloak/startup/elements
             name: elements 
         ports:
          - name: http
            containerPort: 8080
          - name: https
            containerPort: 8443
         readinessProbe:
            httpGet:
              path: /auth/realms/master
              port: 8080
      volumes:
        - name: elements
          configMap:
            name: keycloak-elements
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pv-claim   
</code></pre>
<p>but keycloak is starting with H2 embedded database instead of Postgres. if I am using init-container to <code>nslookup</code> on Postgres on deployment file like below :</p>
<pre><code>initContainers:
      - name: init-postgres
        image: busybox
        command: ['sh', '-c', 'until nslookup postgres; do echo waiting for postgres; sleep 2; done;']
</code></pre>
<p>pod is getting stuck at &quot;podinitialization&quot;</p>

Siddhanta Rath
<p>you forget to add the</p>
<pre><code>- name: DB_VENDOR
  value: POSTGRES
</code></pre>
<p>in the deployment YAML file due to that keycloak by default using the H2 database mode.</p>
<p>YAML ref file : <a href="https://github.com/harsh4870/Keycloack-postgres-kubernetes-deployment/blob/main/keycload-deployment.yaml" rel="nofollow noreferrer">https://github.com/harsh4870/Keycloack-postgres-kubernetes-deployment/blob/main/keycload-deployment.yaml</a></p>
