Home > Blockchain >  inject value in 3rd party helm yaml template of Pod kind
inject value in 3rd party helm yaml template of Pod kind

Time:03-12

I am using 3rd party repository bitnami for mysql.

I know that values.yaml can be injected easily, if that yaml is in dependency section.

i.e, if I add dependency in Chart.yaml:

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

and in values.yaml:

mysql:
    auth:
      rootPassword: "12345"
      database: my_database
    primary:
      service:
        type: LoadBalancer

The root password is injected in bitnami/mysql in the proper parameter auth.rootPassword.

but in case I have my own pod.yaml in template folder:

apiVersion: v1
kind: Pod
spec:
  containers:
    - name: mysql-pod
      image: bitnami/mysql

How can I inject this file the password and other parameters, as the same as I did as with values.yaml file.

I need to pass auth.rootPassword, etc...

Also, if there is ability to refer exactly the same pod, that is created on dependency, and not as another instance.

CodePudding user response:

The chart contains a lot of things – a StatefulSet, a matching Service, a PodDisruptionBudget, a ConfigMap, and so on. You can't force that all into a single Pod, and in general you can't refer to things in Helm charts without including them as dependencies as you show originally.

Bitnami also happens to publish a separate bitnami/mysql Docker image that you could list as the image: in a StatefulSet's pod spec, but you would have to reconstruct all of the other machinery in that chart yourself.

Also, if there is ability to refer exactly the same pod, that is created on dependency, and not as another instance.

There's a typical convention in Helm that most objects are named RELEASE-CHART-SUFFIX, squashing together RELEASE and CHART if they're the same. You don't usually care about the StatefulSet's generated Pod so much as the Service that reaches it, which is generated by a typical Helm Service YAML file. If you're not setting various overrides, and aren't using replicated mode, then in this dependency context, you can combine .Release.Name and the dependency chart name mysql and no suffix to get

- name: MYSQL_HOST
  value: {{ .Release.Name }}-mysql

I'm not aware of a more general way to get the Service's name. (I'm not aware of any charts at all that use Helm's exports mechanism and since it only republishes values it couldn't contain computed values in any case.)

For other details like the credentials, you can either refer to the generated Secret, or just use the .Values.mysql... directly.

- name: MYSQL_USER
  value: {{ .Values.mysql.auth.username }}
- name: MYSQL_PASSWORD
  valueFrom:
    secretKeyRef:
      name: {{ .Release.Name }}-mysql
      key: mysql-password

I don't think there's a good way to figure out these names without either reading the chart's source yourself, observing what the chart actually installs, or reading the chart's documentation (the Bitnami charts are fairly well-documented but others may not be).

  • Related