deploy-kubernetes-using-helm

Deploy microservice to Kubernetes using Helm Charts

In my previous post , I described  Helm and how it works and how to add it to  microservice. In this post, I am going to show how to deploy an application to Kubernetes using Helm.

Deploying of  Microservice with Helm

First you have to a Kubernetes cluster running. This can be on your local machine or in the cloud. I am using Azure Kubernetes Service. for how to set  up Kubernetes look to my post  Azure Kubernetes Service (AKS)  and set up a cluster on Azure.

Before all, you have to install Helm. You can use chocolatey on Windows to install it.

If you haven’t chocolatey you have to install it. for installation look to the chocolatey.org 

After installation the choco is available for installation of helm.

Start Command line (or Windows PowerShell) as administrator and run the following:

choco install kubernetes-helm

For installation in other operating systems, look to the  Helm download page

Deploy your Microservice application with Helm

Open the charts folder of your application. In my case ProductMicroservice, the path is ProductMicroservice/ProductMicroservice/charts. There you have find a folder named productmicroservice. This folder contains the Helm package. Open Windows Powershell as admin and got to this folder. To install this package use helm install [Name] [ChartName]. For me is  productmicroservice application this can be done with the following command:

Obs! run this command if it is not installed before

helm install product productmicroservice

If success then you can get something like the following:

NAME: productmicroservice
LAST DEPLOYED: Thu May 12 13:58:46 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

If it is success, then package is deployed within seconds. After it is finished, connect to the dashboard of your cluster. If you don’t know how to do that, see my post Azure Kubernetes Service (AKS) . There I explain how I use Octant and how to access your Kubernetes cluster.

Change the Configuration of the Helm Chart

You can find the values.yaml file inside the productmicroservice Helm chart. This file provides a way to override the values of the configuration. Under the image section, edit the repository and the tag to use the correct ones:

image:
repository: mehzan07/productmicroservice
tag: latest
pullPolicy: IfNotPresent

We should update the deployment with Helm upgrade again.

Expose Application to the Outside

We should update the Service type, in the values.yaml file (under charts) again and find the service section. Update the type from ClusterIP to LoadBalancer  and save the file.

We should do this because to access to the application from the outside.

see the following:

service
type: LoadBalancer
port: 80

After that Update the deployment with Helm upgrade again.

Update Helm Deployment

because of changes, we should re-deploy the Helm chart, to  update of an existing deployment use helm upgrade [Name] [ChartName] as following:

helm upgrade productmicroservice productmicroservice

Open the dashboard (by starting octant from the start menu) then  look to the Service  productmicroservice  then you can see the following:

deploy-kubernetes-using-helm
Deploy of productmicroservice on Helm chart.

As you see Service productmicroservice has got an external IP address: 20.240.23.56.

If you look to the pods then you can see that all the 3 pods are running as following:

deploy-kubernetes-using-helm-2
Pods for productmicroservice

Testing deployed Application

Testing can be done by two way:

Internal test by “Start Port Forward”,  the dashboard allows us to enable port forwarding for the pod by clicking on the button “Start Port Forward”. Now click to this button which gives you a URL that will forward to your application.

The URL is like : http:// localhost:63662. by opening this URL we will see the Swagger UI of the ProductMicroservice API.

productmicroservice Swagger UI by port forwarding

2- The second way is starting the URL of Service via External IP address  to access the application from outside (that is because we have done “Expose Application to the Outside”).

To find the external IP for Service you can do as following alternatives:

  1. use kubectl to get the service IP

use the following command in Powershell:

kubectl get svc -w productmicroservice

This can give you:

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP PORT(S)     
productmicroservice LoadBalancer 10.0.45.33      20.240.23.56

2- Alternative 2:  open the Service in the dashboard and there you can see the external IP (In this case: (20.240.23.56), Port (80)

Start browser with url: 20.240.23.56:80 then  your browser  shall show you the Swagger UI loaded.

deploy-kubernetes-using-helm-13.png.png
Swagger UI loaded with External IP address of Service

Cleanup all resources

Delete all created resources for AKS in your Azure account.

Conclusion

Helm for Kubernetes is a package manager, which can help you to easily deploy and update  applications.  We have seen how to  update the configuration with the values.yaml file and how to make our application publicly accessible with the Kubernetes Service object.

In my next post , I am going to describe, How to override Appsettings in Kubernetes

The code shall be found on my  GitHub.

This post is part of “Kubernetes step by step”.

Back to home page

Leave a Reply

Your email address will not be published. Required fields are marked *