Lets try to install a Node js application that uses Mongo DB as database using Helm chart in Kubernetes.

I am purging the HelloWorld application created in Part 1 article by entering the below command :
----------------------------------------------helm delete --purge hellohelm100

----------------------------------------------

This will delete the pods and services in kubernetes which are created for the specific application.

Download the source code for the node js application and Dockerfile from my github repository : https://github.com/makandas/nodemongo. Save the files to folder "sample". When the application is accessed in a browser, it should access a database "admin" in mongodb exposed as a service in Kubernetes and display the database records. Your application should take care of creating the database and inserting records into it.

To deploy the application, we need to dockerize the node js application and push the image to docker hub. Login to docker hub by entering the command "docker login" in command prompt and enter your username and password. After login succeeds, lets build the docker image :

Chart.yaml contains the general charts information like chart description, name and version.

values.yaml contains the values specific to your deployment. Example, it can contain the image repository to pull and other service information.

templates/deployment.yaml contains the values specific to container. Example, it can contain livelinessProbe, readinessProbe, and other dependencies information etc.

To deploy this application, edit the values.yaml file with image repository information and expose the service in a Port number. The application is internally exposed in port : 3000 (as same as the value in Dockerfile) and externally exposed in port 80 with type : LoadBalancer.

Since the application has dependencies with Mongodb, create a file requirements.yaml and folder templates and create a file deployment.yaml with values as below :
-------------------------------------------------------

Here, I am passing the values for Mongodb host, port, username, password as values or as arguments during installation. The ideal way is to create Mongodb secrets in Kubernetes and access the secret values. Now, lets install the helm chart to install this application. Before that we need to download all dependencies by entering the following command.

In this article, I will show you how to deploy an application in Kubernetes using Helm Chart. Helm is a Kubernetes-based package installer. It manages Kubernetes “charts”, which are “preconfigured packages of Kubernetes resources.” Helm enables you to easily install packages, make revisions, and even roll back complex changes.

Now, lets create a sample "Hello World" application. Download the source code for the node js application and Dockerfile from my github repository : https://github.com/makandas/HelloWorld. Save the files to folder "sample". When the application is accessed in a browser, it should display the message "Hello World".

We need to dockerize the node js application and push the image to docker hub. Create an account in docker hub. Login to docker hub by entering the command "docker login" in command prompt and enter your username and password. After login succeeds, lets build the docker image :

To deploy this application, it is enough to edit only the values.yaml file with image repository information and expose the service in a Port number. The application is internally exposed in port : 3000 (as same as the value in Dockerfile) and externally exposed in port 80 with type : LoadBalancer.

root@tofu1:~/brokerage# kubectl logs hellohelm100-hellochart-6697979cdd-pl2vj
Received request for URL: /
Received request for URL: /
Received request for URL: /
Received request for URL: /
Received request for URL: /