<p>As <a href="https://hub.docker.com/_/postgres" rel="nofollow noreferrer">the documentation</a> shows, you should be setting the env vars when doing a <code>docker run</code> like the following:</p>

<pre><code>docker run --name some-postgres -e POSTGRES_PASSWORD='foo' POSTGRES_USER='bar'
</code></pre>

<p>This sets the superuser and password to access the database instead of the defaults of <code>POSTGRES_PASSWORD=''</code> and <code>POSTGRES_USER='postgres'</code>.</p>

<p>However, I'm using Skaffold to spin up a k8s cluster and I'm trying to figure out how to do something similar. How does one go about doing this for Kubernetes and Skaffold?</p>

cjones
<p>Use the below YAML</p>

<pre><code>apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  replicas: 1
  template:
    metadata:
      labels:
       name: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:11.2
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: "sampledb"
            - name: POSTGRES_USER
              value: "postgres"
            - name: POSTGRES_PASSWORD
              value: "secret"
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql
      volumes:
        - name: data
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  type: ClusterIP
  ports:
    - port: 5432
  selector:
    name: postgres
</code></pre>
