11

I am using this chart : https://github.com/helm/charts/tree/master/stable/prometheus-mongodb-exporter

This chart requires MONGODB_URI environment variable or mongodb.uri populated in values.yaml file, Since this is a connection string I don't want to check-in that into git. I was thinking of kubernetes secrets and provide the connection string from kubernetes secrets. I have not been able to successfully find a solution for this one.

I also tried creating another helm chart and using this one as a dependency for that chart and provide value for MONGODB_URI from secrets.yaml but that also didn't work because in prometheus-mongodb-exporter chart MONGODB_URI is defined as a required value which is then passed into secrets.yaml file within that chart, so dependency chart never gets installed because of that.

What would be the best way of achieving this?

Asav Patel
  • 1,113
  • 1
  • 7
  • 25
  • After a few years, have you found any better approach to do this? I have the same exact situation. – Mohammed Noureldin Aug 21 '22 at 10:37
  • @MohammedNoureldin I have stored my credentials on Vault and then inject those credentials into the chart at deployment time from the build job (Jenkins). – Asav Patel Aug 23 '22 at 16:28

1 Answers1

4

Solution 1: Create custom chart


  1. Delete the secret.yaml from chart's template directory.
  2. Create the k8s secret on your own, maybe named cumstom-secret
  3. Edit the deployment.yaml: here
       - name: MONGODB_URI
         valueFrom:
           secretKeyRef:
             name: custom-secret ## {{ include "prometheus-mongodb-exporter.fullname" . }}##
             key: mongodb-uri

Solution 2: Use original chart


  1. Set a dummy value for mongodb.uri in value.yaml.
  2. Use --set flag to overwrite the dummy value with original while installing the chart. So, your git won't have the history.
$ helm install prometheus-mongodb-exporter stable/prometheus-mongodb-exporter --set mongodb.uri=******
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • so I have to copy original chart when creating custom chart? it's not possible to create a custom chart with original chart added as dependency? – Asav Patel Feb 04 '20 at 17:43
  • @AsavPatel no, by custom chart I meant, copy the chart some directory, edit it. And then deploy it from there. Just go to the chart directory and use `helm install `. No need use `repo` name like `stable`. – Kamol Hasan Feb 05 '20 at 03:55
  • 5
    Side note. Set command will store values in config-map instead of secret. – wtrocki Nov 11 '21 at 09:58
  • 2
    No better solution by the end of 2022? seems like awkward solution to me. – Mohammed Noureldin Aug 21 '22 at 16:18