Helm Dependency


Helm Dependency

In this tutorial, we are going to discuss about helm dependency. As we discussed earlier as a part of helm I’ll be maintaining a chart and within chart I can maintain n number of sub charts. And I can manually go ahead and create the sub chart and maintain the charts as modules. So that I will be having the separation of the concern.

Helm Dependency

Now, having the sub chart being maintained as a part of the main chart is going to be little tedious when I’m going to have more number of sub charts.

Rather, I can maintain the sub chart as another chart and maintain that as a separate project and add that as a dependency. So I can add another chart as a dependency something like depends on chart XYZ:1.0.

On the chart XYZ, It can be managed as a separate master chart. So when that is being managed the chart itself can be managed as a separate project that can be added within the repository and different versions can be managed and maintained.

So I can add the dependency of that particular chart within the main chart and automatically helm can import those charts. This is what will be handled within the dependency.

Example

Let’s go ahead and see a small demo. I’m going to create a sample chart. Let me create a chart with the name dependencytest.

[email protected]:~$ helm create dependencytest
Creating dependencytest

So I can install this particular chart.

[email protected]:~$ helm install mydeptestinstall ./dependencytest --set service.type=NodePort
NAME: mydeptestinstall
LAST DEPLOYED: Tue Jun  1 10:06:41 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services mydeptestinstall-dependencytest)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT 

This time I’m going to set the service type as NodePort. So what will happen it’ll attach the service port to the NodePort. So that I will be in a position to access that specific service. And the name of the install is mydeptestinstall.

So by default the sample chart, going to create an nginx and it will get deployed in the NodePort. So this particular service is deployed as a part of NodePort.

[email protected]:~$ kubectl get services
NAME                              TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
mydeptestinstall-dependencytest   NodePort   10.152.183.26           80:31022/TCP   5m20s

And it is serving in port 31022. And it is running in this specific machine. So this is the port I will be in a position to access nginx.

Helm Dependency

Now, let me go ahead and update the values file. I’m getting into the chart. I’m updating the values file as a part of repository. Let me go ahead and change the repository to my own project and tag as 1.0.0 as a part of my docker hub repository. I do have this particular application to do.

[email protected]:~/dependencytest$ cat values.yaml 
replicaCount: 1
image:
  repository: waytoeasylearn/todo
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "1.0.0"
imagePullSecrets: []
nameOverride: ""
.................
.................

Lets assume this particular application depends on another image. Say mariadb I need to add the dependency as a part of the charts.yaml file. Now I have this particular repository. Let me go ahead and update the charts.yaml file.

Here I need to add the dependency. So I have added the dependencies and the name of the dependency is mariadb the version and repository in Chart.yaml.

[email protected]:~/dependencytest$ cat Chart.yaml 
apiVersion: v2
name: dependencytest
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0
dependencies:
name: mariadb
version: 7.x.x
repository: https://kubernetes-charts.storage.googleapis.com/ 

Now I can go ahead and deploy this particular chart. And before that, I need to do the build of this particular dependency. So that it can import this required dependent charts.

Dependency building
[email protected]:~$ helm dependency build ./dependencytest/
Hang tight while we grab the latest from your chart repositories…
…Successfully got an update from the "mychartmuseumrepo" chart repository
…Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 1 charts
Downloading mariadb from repo https://charts.helm.sh/stable
Deleting outdated charts

So it’s going to do the update of the repository and all the dependency chart as well. It identified it depends on mariadb. So it’s going to pull the mariadb dependent chart and any outdated charts which are there in the cache will also get deleted.

Now, if I get into this particular folder within charts, I should have the mariadb imported.

[email protected]oeasylearn:~/dependencytest/charts$ ls
mariadb-7.3.14.tgz

This way I will be in a position to maintain the sub chart as a separate project and that can follow its own lifecycle.

And in case, if I feel any of the versions or any change happen to the charts.yaml file or on the dependent charts I can go ahead and do the update using the following command

[email protected]:~$ helm dependency update ./dependencytest/
Hang tight while we grab the latest from your chart repositories…
…Successfully got an update from the "mychartmuseumrepo" chart repository
…Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 1 charts
Downloading mariadb from repo https://charts.helm.sh/stable
Deleting outdated charts

Now using this particular chart, I can go ahead and do the deployment.

[email protected]:~$ helm install mydepwithmaria ./dependencytest --set service.type=NodePort
NAME: mydepwithmaria
LAST DEPLOYED: Wed Jun  2 12:48:49 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services mydepwithmaria-dependencytest)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT 

Let me go ahead and list the pods that got deployed

[email protected]:~$ kubectl get pods
NAME                                               READY   STATUS    RESTARTS   AGE
mydeptestinstall-dependencytest-589db44fc6-4tg4f   1/1     Running   6          26h
mydepwithmaria-dependencytest-5db88db6cf-mxdwn     1/1     Running   0          4m50s
mydepwithmaria-mariadb-master-0                    1/1     Running   0          4m50s
mydepwithmaria-mariadb-slave-0                     1/1     Running   0          4m50s

So as a part of the pods I should have this particular pod mydepwithmaria. Here I do have the mariadb that is getting deployed, master and slave. The same way I will be having the required services and the required components.

So this is biggest advantage of maintaining the dependency. I can maintain all the dependent projects and automatically helm going to import that specific chart and deploy them together. So that the maintenance of the sub chart will also be much easier and it can follow its own lifecycle And the main project can follow its own lifecycle.

And the dependency command of build and update will facilitate to keep the dependent charts up to date. Now let me go ahead and delete those installations.

[email protected]:~$ helm uninstall mydeptestinstall mydepwithmaria
release "mydeptestinstall" uninstalled
release "mydepwithmaria" uninstalled

We do not have any installation. Let me check the Kubernetes cluster as well.

[email protected]:~$ kubectl get all
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.152.183.1           443/TCP   12d

Here also the services, pods and other components are removed.

Summary

So in a quick summary we discussed about how to maintain the dependency and how to add the dependency details as a part of the chart.yaml file and how to add the dependency as a part of the charts.yaml file and how to keep the dependency up to date using the update command and build it in the beginning using the built command.

Helm Dependency


Scroll to top