Learnitweb

Helm in action

Working with Helm Chart Repositories

Introduction

In this tutorial, you will learn how to work with Helm chart repositories. Helm is a package manager for Kubernetes, and it allows you to manage and deploy applications using charts.

Prerequisites

Ensure you have Helm installed on your system. You can verify this by running:

helm version

If Helm is not installed, refer to the official Helm installation guide.

Listing Helm Repositories

To check the repositories Helm is configured to use, run:

helm repo list

Expected Output:

If no repositories are configured, you will see an error message like:

Error: no repositories to show

This happens because Helm, starting from version 3.0, does not come with any pre-configured repositories.

Adding a Helm Repository

To add a repository, use the following command:

helm repo add <repo-name> <repo-url>

For example, to add the Bitnami repository:

helm repo add bitnami https://charts.bitnami.com/bitnami

Explanation:

  • <repo-name>: A user-defined name for the repository (e.g., bitnami).
  • <repo-url>: The URL of the repository (in this case, https://charts.bitnami.com/bitnami).
  • You can choose any meaningful name for the repository instead of bitnami.

Verifying the Added Repository

Once added, verify that the repository is listed:

helm repo list

Expected Output:

NAME    URL
bitnami https://charts.bitnami.com/bitnami

Searching for Charts in a Repository

To search for a chart within a repository, use:

helm search repo <chart-name>

For example, to search for the Apache chart:

helm search repo apache

Expected Output:

NAME                    CHART VERSION   APP VERSION DESCRIPTION
bitnami/apache          10.0.0          2.4.52      Chart for Apache HTTP Server
...
  • CHART VERSION: Version of the Helm chart.
  • APP VERSION: Version of the Apache application.
  • The search results include other charts that mention “Apache” in their description.

Searching for MySQL Charts

helm search repo mysql

This will return results for MySQL and other related charts like MariaDB since “MySQL” appears in their descriptions.

Viewing All Chart Versions

By default, Helm shows only the latest version of a chart. To see all available versions, use:

helm search repo mysql --versions

Expected Output:

NAME                    CHART VERSION   APP VERSION DESCRIPTION
bitnami/mysql           8.8.0           8.0.32      Chart for MySQL
bitnami/mysql           8.7.0           8.0.30      Chart for MySQL
...

This allows you to choose an older version if needed.

Removing a Helm Repository

To remove a repository, use:

helm repo remove <repo-name>

For example:

helm repo remove bitnami

Verifying Removal

Run the following command to confirm:

helm repo list

If all repositories have been removed, you will see:

Error: no repositories to show

Installing a Package in Kubernetes using Helm

You will learn how to install a package on a Kubernetes cluster using the helm install command. Installing a Helm package means deploying an instance of a chart in your cluster.

In this case, we will install the MySQL package using the MySQL chart from the Bitnami repository.

Prerequisites

  • A running Kubernetes cluster (Minikube is used in this example).
  • Helm installed on your machine.
  • Kubectl installed and configured to interact with your cluster.

Step 1: Setting Up Command Line Windows

To follow along efficiently, open three terminal windows (or three tabs if using macOS or Linux):

  1. First Terminal: To monitor Kubernetes resources.
  2. Second Terminal: To access the Minikube Kubernetes node.
  3. Third Terminal: To connect to the MySQL database.

Step 2: Checking for Existing Resources

In the first terminal, check if any pods are running:

kubectl get pods

Expected Output:

No resources found

Since we haven’t installed anything yet, no resources are available.

Step 3: Checking Docker Images on Minikube

Switch to the second terminal and connect to the Minikube node:

minikube ssh

Once inside the Minikube node, check the available Docker images:

docker images

You will only see the default images that come with Minikube. No MySQL image will be present yet.

Step 4: Installing MySQL using Helm

Switch back to the first terminal and execute the following command to install MySQL using Helm:

helm install mydb bitnami/mysql
  • mydb: The name of your Helm release (should be unique within the namespace).
  • bitnami/mysql: The Helm chart to be installed.

This command deploys MySQL using the latest available chart version.

Output:

Helm will perform various tasks in the background and provide a log with installation details. Copy the log and save it in a text editor for reference.

Step 5: Verifying the Installation

Check the deployment status:

kubectl get pods

Expected Output:

You should now see a running MySQL pod:

NAME        READY   STATUS    RESTARTS   AGE
mydb-mysql-0 1/1     Running   0          30s

Step 6: Launching a MySQL Client Pod

To interact with the MySQL database, launch a client pod using:

kubectl run mydb-mysql-client --rm -it --image=bitnami/mysql -- bash
  • This command creates a temporary pod running the MySQL client.
  • Once you exit, the pod will be removed automatically.

Step 7: Connecting to MySQL

Inside the MySQL client pod, execute:

mysql -h mydb-mysql -u root -p

Step 8: Verifying Docker Images in Minikube

Return to the Minikube node (second terminal) and check for new Docker images:

docker images

You should now see the Bitnami MySQL image downloaded and available.

Step 9: Checking Helm Installation Status

To review Helm installation details at any time, run:

helm status mydb

This command displays the deployment details, including connection information and environment settings.

Configuring Helm Charts with Custom Values in Kubernetes

When deploying applications using Helm charts in Kubernetes, default configurations are often provided. However, these defaults may not always meet your requirements. In this tutorial, you will learn how to pass custom configurations when installing Helm packages. Specifically, we will demonstrate setting a custom MySQL root password instead of using the default generated password.

Installing MySQL with a Custom Password

Using the --set Flag (Quick Method)

You can override default Helm chart configurations using the --set flag. For example, to set a custom root password when installing the MySQL chart from Bitnami:

helm install mydb bitnami/mysql --set auth.rootPassword=test1234

This method is convenient for quick changes but is not ideal for managing multiple configurations.

Using a YAML File (Recommended Method)

A more structured way to configure Helm charts is by using a values.yaml file. This allows for better organization and version control of configurations.

  • Create a new YAML file named values.yaml with the following content:
auth:
  rootPassword: "test1234"
  • Install MySQL using the values.yaml file:
helm install mydb bitnami/mysql --values values.yaml

This approach makes it easier to manage configurations and track changes over time.

Verifying the Installation

After installation, you can check the password that was set by running:

echo $(kubectl get secret --namespace default mydb-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)

This should output test1234, confirming that the custom password was successfully applied.

Connecting to MySQL

To connect to MySQL from a client pod:

  • Deploy a MySQL client pod:
kubectl run mydb-client --rm -it --image=mysql -- bash
  • Inside the pod, connect to the MySQL server:
mysql -h mydb-mysql -u root -p

Enter the password test1234 when prompted.

  • You can now run MySQL commands, such as creating a database:
CREATE DATABASE test_db;
SHOW DATABASES;