Deploying App to Google Kubernetes Engine using Helm Charts | HCLTech
Engineering

Deploying App to Google Kubernetes Engine using Helm Charts

In this blog, you will learn how to deploy node.js application into Kubernetes Engine using Helm charts.
 
5 minutes read
Thummala Hareesh

Author

Thummala Hareesh
Technical Engineer
5 minutes read
Share

Introduction

In this blog, you will learn how to deploy node.js application into Kubernetes engine using Helm charts. Before helm charts, users need to run the YAML files like deployment.yaml, service.yaml, ingress.yaml and dns.yaml individually. Now we can run all the files together using Helm Chart with a single command. This way, we can save a lot of time and reuse this chart in multiple environments.

Prerequisites:

  1. GCP free tier account
  2. Create a Google Cloud Platform (GCP) project or use an existing one.
  3. Enable the following APIs
    1. Kubernetes Engine API.
    2. Container registry API.
  4. Basics of Kubernetes & Helm

Helm Chart

Helm is a Kubernetes-based package installer. It manages Kubernetes “Charts”, which are pre-configured packages of Kubernetes resources. Helm enables you to easily install packages and make revisions.

Google Kubernetes Engine(GKE)

Google Kubernetes Engine(GKE) is used to manage the containers, like managing to start the containers, run and deploy the containers manually. It’s very difficult for us doing automation through the Google Kubernetes engine.

Container Registry

Container Registry is a service of Google cloud and its storing container images.

Helm installation

  1. Navigate the GCP console.
  2. hit on the Cloud Shell Distortion button
  3. To download the latest version, use the wget command
    wget https://get.helm.sh/helm-v3.9.3-linux-amd64.tar.gz
  4. Using the tar command, unzip the .gz files.
    tar xvf helm-v3.9.3-linux-amd64.tar.gz
  5. Move the linux-amd64/helm file to the /usr/local/bin directory:
    sudo mv linux-amd64/helm /usr/local/bin
  6. To check the version of Helm, use the below command
    helm version

Create a Kubernetes Cluster and connect to cloud Shell

In this step, we need to deploy our application through helm charts. So, it supports Kubernetes Engine and then creates a cluster to use Cloud shell (or) console.

Type 1: Using Cloud Shell

  1. Set your Region
    gcloud config set compute/region REGION
  2. Create cluster name as my-app
    gcloud container clusters create-auto my-app

Type 2: using the GCP console

  1. Go to the Kubernetes Engine in GCP Console.
  2. Now hit on the “Create cluster”.
  3. enter the name as my-app
  4. Click Create.

Distortion

Once cluster created then Use the below command to connect cluster in cloud shell
gcloud container clusters get-credentials my-app –zone us-central1-c

Distortion

Create an application:

We need an application to deploy on our cluster. We will create a simple Node.JS app in this section.

Open Shell Distortion here; we will create a directory for our app using the below commands
mkdir my-app && cd my_app

Now create the following files in the my-app directory:

server.js file to store our app code:

Distortion

package.json file to store the metadata of our app and its dependencies:

Distortion

Dockerfile file to describe the docker image of our application:

Distortion

Now we have three files in the `my_app` directory

  1. Server.js
  2. Package.json
  3. Dockerfile

Build the Docker Image:

Now to create Docker image use below “build” command:

docker build –t IMAGE_NAME

now check the images using the below command

docker images

Pushing Docker Image To Container Registry:

now we need to push the image to the container registry using the below commands

docker tag IMAGE_NAME gcr.io/PROJECT_ID/IMAGE_NAME

docker push gcr.io/PROJECT_ID/IMAGE_NAME

now you can check images in the container registry

  1. Hit on left side menu bar, scroll down
  2. Hit on Container Registry.

Distortion

Create a Helm Chart

Helm allows us to template our Kubernetes resources manifest files. A standard Helm chart has the following structure:

Distortion

  1. Templates: Templates folder have multiple yaml files like deployment.yaml, service.yaml, ingress.yaml, secret.yaml and dns.yaml for application deployment. They will all get their values from values.yaml from above.
  2. Chart.yaml: It is all the information about the chart being packaged. Here we need to mention our chart name and version.
  3. Values.yaml: This file can be edited to customize the configuration of a chart, or the values can be passed in as arguments during the installation of the chart.
  4. Charts: If your chart is dependent on some other charts, this is where you store them. You will be calling another chart for your chart to function properly.

deployment.yaml

Distortion

Service.yaml

Distortion

Chart.yaml

Distortion

Values.yaml

Distortion

Deploy the Helm chart

Now helm chart is ready to deploy once we run this command helm install my-app. Our node.js application will be deployed on the GKE.

Distortion

Now our application is deployed, you can check the status in the above screenshot, and You can confirm this by navigating to the console for verification.

Console🡪Kubernetes Engine->Workloads

Distortion

Console🡪Kubernetes Engine->Service&ingress

Distortion

Here we have Load Balancer’s public IP; now, we will see the output.

Output

Now you can use the curl command or simply use your browser to check the output. You should see a pretty "Hello World":

Distortion

Finally, we deployed our Node.js application into Google Kubernetes Engine using the Helm Charts method.

Using this Helm chart method, we can easily deploy our applications into multiple environments

  1. The DevOps team once created the helm chart, can use it for multiple environments like development, testing and production etc.
  2. Helm chart makes it easy to modify default values in the values.yaml file
  3. As per requirements, the users and developers can take changes while installing the helm charts

References:

  1. Helm: Helm Overview
  2. Google Kubernetes Engine: Google Kubernetes Engine (GKE) | Google Cloud
  3. Container Registry: Container Registry | Google Cloud
  4. Free Tier account: Free Google Cloud Platform Account | Google Cloud Free Account Steps
TAGS:
Engineering and R&D services
Share On