While creating pod for postgres , pod going to error state

Hi ,

i am getting the error below .How can i handle it ?
I tried to execute voting-webapp on google cloud .Everything went fine except postgres pod is going to error state .
i checked logs .

satyam_saty143@cloudshell:~/K8s/example-voting-app-kub (innate-buckeye-276109)$ kubectl logs postgres-pod
Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, “-e POSTGRES_PASSWORD=password” on “docker run”.

   You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
   connections without a password. This is *not* recommended.

   See PostgreSQL documentation about "trust":

please help how to fix it .

provide a password. can you share your yaml file here. Use configmap and pass it into deployment definition yaml file env section.

apiVersion: v1
kind: Pod
metadata:
name: postgres-pod
labels:
name: postgres-pod
app: demo-voting-app
spec:
containers:
- name: postgres
image: postgres:9.4
ports:
- containerPort: 5432

apiVersion: v1
kind: Pod
metadata:
name: postgres-pod
labels:
name: postgres-pod
app: demo-voting-app
spec:
containers:
- name: postgres
image: postgres:alpine
environment:
POSTGRES_HOST_AUTH_METHOD: trust

even i tried adding this .

apiVersion: v1
kind: Pod
metadata:
name: postgres-pod
labels:
name: postgres-pod
app: demo-voting-app
spec:
containers:
- name: postgres
image: postgres:9.4
ports:
- containerPort: 5432
environment:
- POSTGRES_PASSWORD= add password here
1 Like

Thnks …

apiVersion: v1
kind: Pod
metadata:
name: postgres-pod
labels:
name: postgres-pod
app: demo-voting-app
spec:
containers:
- name: postgres
image: postgres
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: “postgres”
- name: POSTGRES_PASSWORD
value: “postgres”
- name: POSTGRES_HOST_AUTH_METHOD
value: trust

You have to pass the postgres_host_auth_method as an array item. This worked for me without having to use a deployment.