Search code examples
kubernetes-helm

Get MySQL service/password/user from Helm dependency


I would like to add https://hub.helm.sh/charts/bitnami/mysql as a dependency to my helm charts. So I added this to my Chart.yaml:

dependencies:
- name: mysql
  version: "6.14.9"
  repository: "https://charts.bitnami.com/bitnami"

How can I now get the service name the password and the user as environment variables in my main chart deployments to connect to the mysql server? Somehow all the documentation of the chart only ever mentions directly installing it with helm. Is it not correct to use a dependency here?


Solution

  • When you are using a dependency you can override the values.yaml for mysql chart from the parent chart and then inject those values as an environment variable or a secret into your main container.

    in values.yaml of parent chart

    mysql:
     mysqlRootPassword: testing
     mysqlUser: user
     mysqlPassword: user
     
    

    once you have these values you can use these values to create a secret and user volume mount or directly inject them as an environment variables.

    For mysql server use the release name and chart name for most of the cases unless you are using a NameOverride or FullNameOverride

     env:
      - name: MYSQL_SERVER
        value: {{ .Release.Name }}-mysql