Home > Net >  How to pass data between two helm charts?
How to pass data between two helm charts?

Time:06-21

I have two helm charts, I need to generate a random password in one of the charts, and I am required to use the same password in the second.

What would be the best practice to achieve this?

Thanks in advance!!

CodePudding user response:

Generate the password in a known secret name then refer to that secret in the other chart?

CodePudding user response:

You have several options to achieve this requirement.

  1. If you are using Helm you can deploy resources to the same Namespace and store the password in a configMap or in Secret. The ConfigMap / Secret will be generated dynamically during the creation or deployment of the chart

  2. Another solution might be to use Helm Dependency. Helm dependency allows you to build up the charts with dependencies between each other so you can pass information between them.

  3. Use kubectl kustomization to generate the ConfigMap / Secret and share them between the charts. The best approach is to use kustomisation hierarchy which will allow you to share the content.

For example:

  • You can set up and .env with the random value
# Generate random number and store it inside `ConfigMap`
echo $RANDOM > .env
  • Use the .env to generate the different secrets per chart

# reference: [https://github.com/nirgeier/KubernetesLabs/tree/master/Labs/08-Kustomization/samples/03-generators/ConfigMap/01-FromEnv]


# kustomization.yaml for ConfigMap
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

configMapGenerator:
  # Generate config file from the env file which you 
  # created in teh previous step
  - name: configMapFromEnv
    env: .env
  • Now you will have the same "password" in both of the charts.
  • Related