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.
If you are using Helm you can deploy resources to the same Namespace and store the password in a
configMap
or inSecret
. TheConfigMap
/Secret
will be generated dynamically during the creation or deployment of the chartAnother 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.
Use
kubectl kustomization
to generate theConfigMap
/Secret
and share them between the charts. The best approach is to usekustomisation
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.