What's Helm?
Helm is the package manager of Kubernetes. Like package management tools such as yum and apt, helm can easily deploy the applications we want with one click.
Writing Helm has three main goals:
1. Easily realize "from zero to Kubernetes";
2. Provide a software package management system similar to the operating system;
3. Emphasize the security and configurability of deploying applications to Kubernetes.
A very important element in Helm: Chart
- Chart is Helm's software package, which means nautical chart. Chart is a set of files and directories that follow the chart specification to define the resources to be installed in kubernetes.
- Chart contains a file named chart Yaml file, which describes the version, name, description and some information of the author of this chart.
- chart contains the template, the kubernetes list.
- There is a file in chart that provides the default configuration named values yaml. This file contains parameters that can be overwritten during installation and upgrade and can be modified.
- When you see a chart, it may be a compressed package, like ingress-nginx-4.0.17 Tgz can also be a directory, ingress nginx.
- Its directory structure may look like this:
[root@k8s-master01 ingress-nginx]# ls CHANGELOG.md Chart.yaml ci OWNERS README.md README.md.gotmpl templates values.yaml
When a chart is installed, its process may look like this:
- Helm read chart
- Send the defined values to the template to generate the kubernetes list
- The list is sent to kubernetes
- kubernetes creates the requested resource in the cluster according to the manifest
Using Helm
Helm has v2 and V3 versions. I'll ignore v2 here because I use v3.
Helm provides a command-line tool called helm, which we use to operate.
Precautions for installing helm client
When installing helm, it should be noted that the version of helm should match the version of kubernetes, as shown in the following figure:
Reference for specific version: https://helm.sh/docs/topics/version_skew/
Let's install helm client in binary mode:
Detailed description or other installation reference: https://helm.sh/docs/intro/install/ Official documents
So far, when I install helm, the latest version is 3.8.0, while my k8s cluster version is 1.23 X is exactly the same.
- Download binary package
wget https://get.helm.sh/helm-v3.8.0-linux-amd64.tar.gz
- Unzip binary package
tar xf helm-v3.8.0-linux-amd64.tar.gz
- Move the helm directory in the unzipped directory to / usr/local/bin/helm
mv linux-amd64/helm /usr/local/bin/helm
- After installation, it is easy
Add chart repository
Only one client tool can't work. We also need to know where its chart package comes from, which is equivalent to the software source installed by yum.
- Add an official repository
- Note: the name after add is user-defined, which is convenient for you to remember. It is not fixed
helm repo add bitnami https://charts.bitnami.com/bitnami # Repositories added to my environment [root@k8s-master01 ~]# helm repo list NAME URL ingress-nginx https://kubernetes.github.io/ingress-nginx nginx-stable https://helm.nginx.com/stable bitnami https://charts.bitnami.com/bitnami
- Check whether it is added successfully? In fact, as demonstrated above, this command can check that the storage inventory you added does not exist
helm repo list
Search chart repository
- After adding the library, how can I know that the chart package I want to install does not exist? Use the following command
[root@k8s-master01 ~]# helm search repo apache NAME CHART VERSION APP VERSION DESCRIPTION bitnami/apache 9.0.2 2.4.52 Apache HTTP Server is an open-source HTTP serve... bitnami/airflow 12.0.1 2.2.3 Apache Airflow is a tool to express and execute...
- Of course, you can also try to search for chart packets from the network:
[root@k8s-master01 ~]# helm search hub wordpress URL CHART VERSION APP VERSION DESCRIPTION https://artifacthub.io/packages/helm/kube-wordp... 0.1.0 1.1 this is my wordpress package https://artifacthub.io/packages/helm/bitnami/wo... 13.0.11 5.9.0 WordPress is the world's most popular blogging ...
Install a chart
- The premise of installing chart is to have a namespace. Of course, the default can also be used. In order to distinguish or create a namespace
- Now create a namespace named mysql
kubectl create ns mysql
- Then install the chart package
hellm install my-mysql bitnami/mysql -n mysql
Explain the meaning of this command:
- My MySQL represents the name of the chart I run. It is user-defined
- bitnami/mysql: is the name of the repository plus the package name
- -n mysql: is the name of the specified namespace
After installation, you can check whether the installation is successful:
It should be noted that:
- No matter whether your Pod resource can be created successfully or not, as long as helm is created successfully, this instance will exist
- The instance name in the same namespace is unique. Creating an instance with the same name again will report an error
[root@k8s-master01 ~]# helm list -n mysql NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION my-mysql mysql 1 2022-02-17 14:32:38.423267837 +0800 CST deployed mysql-8.8.23 8.0.28
- This command can view some status of the chart you created:
[root@k8s-master01 ~]# helm status my-mysql -n mysql
- When you don't want this chart, you can also choose to uninstall it:
[root@k8s-master01 ~]# helm uninstall my-mysql -n mysql
Custom configuration installation
The configuration installed by default is often not what we need, so we can pull down the chart package, and then modify the parameters before execution.
- pull down the chart package and decompress it. You can see the basic information in the package
[root@k8s-master01 ~]# helm pull bitnami/mysql [root@k8s-master01 ~]# tar xf mysql-8.8.23.tgz -C /temp/ [root@k8s-master01 ~]# cd /temp/mysql/ [root@k8s-master01 mysql]# ls Chart.lock charts Chart.yaml ci README.md templates values.schema.json values.yaml
- You can modify his values Yaml file, no modification here
- Then execute the modified values Yaml file, because you are executing a local file, you don't need to add the source address
[root@k8s-master01 mysql]# helm install mysql-01 -n mysql .
- If you have run the chart and then modified the yaml file, you can update it with this command
[root@k8s-master01 mysql]# helm upgrade --install mysql-01 -n mysql .
That's it. Let's just talk about the basic use of helm.
In the future, I will write the use of chart and create chart by myself.