0

I just can't figure out why it is working the way it is. If I

  • use POSTGRES_PASSWORD with hardcoded value in environment it works
  • use POSTGRES_PASSWORD from a secret with valueFrom: secretKeyRef: it works
  • use POSTGRES_USER OR POSTGRES_DB with hardcoded values in environment it works

But if I try to use POSTGRES_USER OR POSTGRES_DB from secret it won't work no matter what I do. And yes after each try I cleared the PV so the pod would be regenerated from scratch.

I want my PostgreSQL Deployment to look something like this:

            containers:
                - name: postgresql
                  image: postgres
                  imagePullPolicy: "IfNotPresent"
                  # ports:
                  #     - containerPort: 5432
                  env:
                  - name: POSTGRES_DB
                    value: whatever
                  - name: POSTGRES_USER
                    # value: login
                    valueFrom:
                        secretKeyRef:
                            name: postgresql-credentials
                            key: username
                  - name: POSTGRES_PASSWORD
                    # value: pass
                    valueFrom:
                        secretKeyRef:
                            name: postgresql-credentials
                            key: password

The secret looks like this:

apiVersion: v1
kind: Secret
data:
    username: dXNlcgo=
    password: cGFzcwo=
metadata:
    name: postgresql-credentials

1 Answer 1

0

Solved. After looking at the environment of the pod and noticed that POSTGRES_USER had an empty line below it. Basically you need to base64 encode without newline character.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.