How to Deploy Helm Charts on Google Kubernetes Engine (GKE)


How to Deploy Helm Charts on Google Kubernetes Engine (GKE)

Helm is a package manager for Kubernetes that simplifies the process of deploying, upgrading, and managing applications on your Kubernetes clusters. By using Helm charts, you can define, install, and upgrade even the most complex Kubernetes applications. In this article, we’ll walk through the steps to deploy Helm charts on a Google Kubernetes Engine (GKE) cluster.

Prerequisites

Before you begin, ensure you have the following:

  1. Google Kubernetes Engine (GKE) Cluster: A running GKE cluster. If you don’t have one, you can create it using the GCP Console, Terraform, or the gcloud command-line tool.
  2. Helm Installed: Helm should be installed on your local machine. You can download it from the Helm website.
  3. kubectl Configured: Ensure kubectl is configured to interact with your GKE cluster. You can do this by running:
   gcloud container clusters get-credentials <your-cluster-name> --region <your-region> --project <your-gcp-project-id>

Step 1: Install Helm

If Helm is not already installed, follow these steps:

  1. Download Helm: Visit the Helm releases page and download the appropriate binary for your operating system.
  2. Install Helm: Unpack the Helm binary and move it to a directory in your PATH. For example:
   sudo mv helm /usr/local/bin/helm
  1. Verify Installation: Run the following command to verify Helm is installed correctly:
   helm version

Step 2: Add Helm Repositories

Helm uses repositories to store charts. By default, Helm uses the official Helm stable repository. You can add more repositories depending on your requirements.

helm repo add stable https://charts.helm.sh/stable
helm repo update

This command adds the stable repository and updates your local repository cache.

Step 3: Deploy a Helm Chart

Helm charts make it easy to deploy applications. Let’s deploy a popular application like nginx using a Helm chart.

  1. Search for a Chart: If you don’t know the exact chart name, you can search Helm repositories.
   helm search repo nginx
  1. Deploy the Chart: Once you have identified the chart, you can deploy it using the helm install command. For example, to deploy nginx:
   helm install my-nginx stable/nginx-ingress
  • my-nginx is the release name you assign to this deployment.
  • stable/nginx-ingress is the chart name from the stable repository.
  1. Verify the Deployment: After deploying, you can check the status of your release using:
   helm status my-nginx

You can also use kubectl to view the resources created:

   kubectl get all -l app.kubernetes.io/instance=my-nginx

Step 4: Customize Helm Charts (Optional)

Helm charts can be customized using values files or command-line overrides.

  • Using a values file: Create a custom values.yaml file and pass it during the installation:
  helm install my-nginx stable/nginx-ingress -f values.yaml
  • Using command-line overrides: Override specific values directly in the command:
  helm install my-nginx stable/nginx-ingress --set controller.replicaCount=2

Step 5: Upgrade and Rollback Releases

One of the strengths of Helm is its ability to manage versioned deployments.

  • Upgrading a Release: If you want to upgrade your release to a newer version of the chart or change its configuration:
  helm upgrade my-nginx stable/nginx-ingress --set controller.replicaCount=3
  • Rolling Back a Release: If something goes wrong with an upgrade, you can easily roll back to a previous version:
  helm rollback my-nginx 1

Here, 1 refers to the release revision number you want to roll back to.

Step 6: Uninstall a Helm Release

When you no longer need the application, you can uninstall it using the helm uninstall command:

helm uninstall my-nginx

This command removes all the Kubernetes resources associated with the Helm release.

Conclusion

Deploying Helm charts on GKE simplifies the process of managing Kubernetes applications by providing a consistent, repeatable deployment process. Helm’s powerful features like versioned deployments, rollbacks, and chart customization make it an essential tool for Kubernetes administrators and developers. By following this guide, you should be able to deploy, manage, and scale your applications on GKE with ease.