<p>I have problems in deploying a simple postgres container on minikube. It doesn't create &quot;postgres&quot; database when a persistent volume is mounted:</p>
<pre><code>kubectl exec -it POSTGRES_POD -- sh

/ $ su postgres
/ $ psql
psql: FATAL:  database &quot;postgres&quot; does not exist
</code></pre>
<p>Here is my postgres deployment:</p>
<pre><code>resource &quot;kubernetes_deployment&quot; &quot;backend_postgres&quot; {
  metadata {
    ...
  }

  spec {
    replicas = 1

    ...

    template {
      metadata {
        ...
      }

      spec {
        volume {
          name = &quot;data&quot;

          persistent_volume_claim {
            claim_name = kubernetes_persistent_volume_claim.data.metadata[0].name
          }
        }

        container {
          name  = &quot;postgres&quot;
          image = &quot;postgres:10-alpine&quot;

          port {
            container_port = 5432
          }

          env {
            name = &quot;POSTGRES_PASSWORD&quot;

            value_from {
              secret_key_ref {
                name = kubernetes_secret.postgres_password.metadata[0].name
                key  = &quot;password&quot;
              }
            }
          }
    
          volume_mount {
            name       = &quot;data&quot;
            mount_path = &quot;/var/lib/postgresql/data&quot;
            sub_path   = &quot;postgres&quot;
          }

        }
      }
    }
  }
}
</code></pre>
<p>The persistent volume successfully gets mounted and postgres successfully writes to <code>/var/lib/postgresql/data</code> but as I mentioned earlier, it doesn't create &quot;postgres&quot; database.</p>
<p>But when I don't mount a persistent volume, everything works fine.</p>
<p>Here is my deployment without mounting any persistent volume:</p>
<pre><code>resource &quot;kubernetes_deployment&quot; &quot;backend_postgres&quot; {
  metadata {
    ...
  }

  spec {
    replicas = 1

    ...

    template {
      metadata {
        ...
      }

      spec {

        container {
          name  = &quot;postgres&quot;
          image = &quot;postgres:10-alpine&quot;

          port {
            container_port = 5432
          }

          env {
            name = &quot;POSTGRES_PASSWORD&quot;

            value_from {
              secret_key_ref {
                name = kubernetes_secret.postgres_password.metadata[0].name
                key  = &quot;password&quot;
              }
            }
          }
    
        }
      }
    }
  }
}
</code></pre>
<p>I'm working on this strange scenario for days.</p>
<p>I'm runing the kubernetes cluster on minikube. Any kind of help or suggestion would be really appreciated.</p>

HsnVahedi
<p>Since it is using a persistent volume, it presumably won't be recreating the database instance each time, but rather re-using the one that already exists.  And somehow, the one that already exists isn't configured the way you want it to be.</p>
<p>After making sure that the database is not running anywhere, you could move it all someplace else (because you may discover you actually need it for something) leaving the persistent directory empty.  Then try again and see if it creates a suitable database instance complete with the expected &quot;postgres&quot; database.</p>
