How to add dependency to Helm Chart
Add postgresql chart dependency to helm chart

This is continuation to previous article. If you have not followed earlier steps, I would recommend to refer earlier article
Add dependency
In previous step we created chart for usermanagement application which uses built-in H2 database. However, we would like to use production grade database to have data persistence.
In this step we will add existing bitnami/postgresql chart and use it to provide persistence to our usermanagement application.
Let's add postgresql dependencies to existing Chart.yaml
charts/myapp/Chart.yaml
dependencies:
- name: postgresql
version: "10.13.8"
repository: https://charts.bitnami.com/bitnami
condition: postgresql.enabled
Append below values to existing values.yaml file. This configuration is based on postgresql subchart.
- Make sure you use the same name, give in
Chart.yamldependencies. - You can refer the values.yaml of Postgresql chart
- Parent chart can override the values of sub-chart
If you need to view bitnami/postgresql chart, you can download and unzip on your machine with below command, it creates postgresql charts directory.
You can refer the postgresql/values.yaml to override in your parent chart.
helm pull bitnami/postgresql --untar
charts/myapp/template/values.yaml
postgresql:
enabled: true
global:
postgresql:
postgresqlDatabase: "usersdb"
postgresqlPassword: "Hello@123"
postgresqlUsername: "userservice-pguser"
servicePort: "5432"
UserManagement application uses embedded h2 database with default profile, if external database to be used kyma spring profile needs to be enabled.
- Spring profile
kymaexpects external database configuration with below environment variablesDB_HOST,DB_NAME,MASTER_PASSWORD,MASTER_USERNAME
charts/myapp/template/deployment.yaml
env:
{{- if .Values.postgresql.enabled }}
- name: SPRING_PROFILE
value: "kyma"
- name: DB_HOST
value: "{{ .Release.Name}}-postgresql-headless"
- name: DB_NAME
value: {{ .Values.postgresql.global.postgresql.postgresqlDatabase | quote }}
- name: MASTER_PASSWORD
value: {{ .Values.postgresql.global.postgresql.postgresqlPassword | quote }}
- name: MASTER_USERNAME
value: {{ .Values.postgresql.global.postgresql.postgresqlUsername | quote }}
- name: DB_PORT
value: {{ .Values.postgresql.global.postgresql.servicePort | quote }}
{{- end }}
Build dependency
Let's now build dependency to fetch the sub-chart. This command synchronizes between the desired dependencies and the actual dependencies stored in the charts/myapp/charts/ directory.
helm dependency update charts/myapp
Helm downloads the Postgresql chart postgresql-10.13.8.tgz in charts/myapp/chart directory and adds charts/myapp/Chart.lock file
charts/myapp
├── Chart.lock
├── Chart.yaml
├── charts
│ └── postgresql-10.13.8.tgz
...
Install Chart
Let's install helm chart with dependency to Kubernetes cluster. Below command should create postgresql resources along with usermanagement application.
helm install demo2 charts/myapp
Verify installation
You can follow the NOTES shown after installation and access the application using
Let's check all the resources installed with the helm chart. If you have only demo2 helm release then you should see below resources
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/demo2-postgresql-0 2/2 Running 0 11m
pod/demo2-user-service-c6468c69c-f8zqf 2/2 Running 0 11m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/demo2-postgresql ClusterIP 100.71.10.27 <none> 5432/TCP 11m
service/demo2-postgresql-headless ClusterIP None <none> 5432/TCP 11m
service/demo2-user-service ClusterIP 100.71.31.125 <none> 80/TCP 11m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/demo2-user-service 1/1 1 1 11m
NAME DESIRED CURRENT READY AGE
replicaset.apps/demo2-user-service-c6468c69c 1 1 1 11m
NAME READY AGE
statefulset.apps/demo2-postgresql 1/1 11m
Clean up
As a good practice, let's cleanup the resources with below command
helm uninstall demo2
We saw how we can add sub chart dependency to in your application helm chart. You can try applying to your application by adding other chart dependencies.
In next article, we'll see how we can release the chart so that it can be shared with others and to other Kubernetes cluster environments
You can visit next article on using GitHub Action CI-CD pipeline to package, test, and release helm chart to GitHub pages.



