0

My password placeholder in Application.yaml in spring boot project:

password: {DB_PASSWORD}

My secret file:

apiVersion: v1
data:
  DB_PASSWORD: QXBwX3NhXzA1X2pzZHVlbmRfMzIx
kind: Secret
type: Opaque
metadata:
  name: test-secret

My Deployment config file part:

spec:
      containers:
        - envFrom:
            - configMapRef:
                name: gb-svc-rpt-dtld-cc
          image: >-
            artifactory.global.standardchartered.com/colt/gb-svc-reports-dataloader-cc/gb-svc-reports-dataloader-cc-develop@sha256:c8b7e210c18556155d8314eb41965fac57c1c9560078e3f14bf7407dbde564fb
          imagePullPolicy: Always
          name: gb-svc-rpt-dtld-cc
          ports:
            - containerPort: 8819
              protocol: TCP
          volumeMounts:
            - mountPath: /etc/secret
              name: secret-test
      volumes:
        - name: secret-test
          secret:
            defaultMode: 420
            secretName: test-secret

I'm able to see the secrets added in /etc/secret path also. But it is not getting referred in placeholders and getting error while server startup.

Could not resolve placeholder 'DB_PASSWORD' in value "${DB_PASSWORD}"

Note: Same code works if i add the secret as environment variable in deployment config

  • Is it a specific requirement that you need to mount secrets using volume? Difference is using volume secret is mounted as a file so it will not replace any env variable. [reference](https://www.eclipse.org/che/docs/che-7/end-user-guide/mounting-a-secret-as-a-file-or-an-environment-variable-into-a-workspace-container/) – Neeraj Jain Feb 16 '22 at 11:34
  • So any placeholder added in application.yaml of spring boot service will not get replaced if i add secrets as volume? Sorry, just want to make it clear. – Suddhasatta Dhar Feb 17 '22 at 02:51

1 Answers1

0

As I understand from your question you are trying to mount secret to a pod as an environment variable. In kubernetes secrets are able to mount as a volume (which you did in the attached code) and as env variable (as you like to do)

For that you should use:

spec:
    containers:
    - env:
      - name: DB_PASSWORD
        valueFrom:
          secretKeyRef:
            key: DB_PASSWORD
            name: test-secret
      image: "fedora:29"
      name: my_app
Ron Megini
  • 31
  • 7
  • Hi Ron, My question is bit different. secrets added as env variables is working fine. My problem is when i add secret as volume, it is not getting replaced for placeholders added in application yml in spring boot service. – Suddhasatta Dhar Feb 17 '22 at 02:50