4

In my helm chart, I have a few files that need credentials to be inputted For example

<Resource
    name="jdbc/test"
    auth="Container"
    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    url="jdbc:sqlserver://{{ .Values.DB.host }}:{{ .Values.DB.port }};selectMethod=direct;DatabaseName={{ .Values.DB.name }};User={{ Values.DB.username }};Password={{ .Values.DB.password }}"
    />

I created a secret

Name: databaseinfo
   Data:
     username
     password

I then create environment variables to retrieve those secrets in my deployment.yaml:

env:
   - name: DBPassword
      valueFrom:
      secretKeyRef:
        key: password
        name: databaseinfo
   - name: DBUser
       valueFrom:
       secretKeyRef:
         key: username
         name: databaseinfo 

In my values.yaml or this other file, I need to be able to reference to this secret/environment variable. I tried the following but it does not work: values.yaml

DB:
  username: $env.DBUser
  password: $env.DBPassword
Oplop98
  • 220
  • 1
  • 2
  • 8
  • 1
    Does this answer your question? [How to pull environment variables with Helm charts](https://stackoverflow.com/questions/49928819/how-to-pull-environment-variables-with-helm-charts) – mehowthe Aug 30 '21 at 20:20

1 Answers1

5

you can't pass variables from any template to values.yaml with helm. Just from values.yaml to the templates.

The answer you are seeking was posted by mehowthe :

deployment.yaml =

      env:          
        {{- range .Values.env }}
      - name: {{ .name }}
        value: {{ .value }}
     {{- end }}

values.yaml =

env:          
 - name: "DBUser"
   value: ""
 - name: "DBPassword"
   value: ""

then

helm install chart_name --name release_name --set env.DBUser="FOO" --set env.DBPassword="BAR"

Community
  • 1
  • 1
Philip Welz
  • 2,449
  • 5
  • 12