Doing more with less: understanding and using Helm

What is Helm?

Helm is a package manager for Kubernetes. Similar to 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 achieve from "zero to Kubernetes";
2. Provide a 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. A chart is a set of files and directories that follow the chart specification and are used to define resources to be installed into kubernetes.
  • The chart contains a file called chart.yaml which describes the version, name, description and some information about the author of this chart.
  • A chart contains templates, i.e. kubernetes manifests.
  • There is a file named values.yaml in the chart that provides default configuration. This file contains parameters that can be overridden during installation and upgrade and can be modified.
  • When you see a chart, it may be a compressed package, like this ingress-nginx-4.0.17.tgz, or a directory ingress-nginx.
  • Its directory structure might 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 flow may look like this:

  • Helm reads chart
  • Send defined values ​​to template, generate kubernetes manifest
  • The manifest is sent to kubernetes
  • kubernetes creates the requested resource in the cluster based on the manifest

Using Helm

Helm has v2 and v3 versions, v2 is ignored here because I am using v3.
Helm provides a command line tool called helm that we use to operate.

Notes on installing the helm client

One thing to pay attention to when installing helm, the version of helm should match the version of kubernetes, as shown in the figure below: the
specific version corresponds to the reference: https://helm.sh/docs/topics/version_skew/
insert image description here

Below we install the helm client in binary mode:

For detailed instructions or other installation references: https://helm.sh/docs/intro/install/official documentation
At present, the latest version of helm when I installed it was 3.8.0, and my k8s cluster version was 1.23.x Fully compliant.

  • Download binary package
wget https://get.helm.sh/helm-v3.8.0-linux-amd64.tar.gz
  • Unzip the binary package
tar xf helm-v3.8.0-linux-amd64.tar.gz
  • Move the helm directory in the decompressed directory to /usr/local/bin/helm
mv linux-amd64/helm /usr/local/bin/helm
  • Installation is over, very simple

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 customized for your convenience, not fixed
helm repo add bitnami https://charts.bitnami.com/bitnami

# 我的环境添加的存储库
[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 if the addition is successful? In fact, it has been demonstrated above, this command can check that the storage inventory you have added does not exist
helm repo list

Search the chart repository

  • After adding the library, how can I know whether the chart package I want to install exists or not? 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 packages from the Internet:
[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 that there needs to be a namespace, of course, the default can also be, in order to distinguish or create a
  • Next create a namespace called mysql
kubectl create ns mysql
  • Then install the chart package
hellm install my-mysql bitnami/mysql -n mysql

Tell me what this command means:

  • my-mysql represents the name of the chart I am running, which is customized
  • 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 was successful:

have to be aware of is:

  • Regardless of whether your Pod resource can be created successfully, as long as helm is created successfully, the instance will exist
  • Instance names within the same namespace are unique, and an error will be reported when an instance with the same name is created again
[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 default installed configuration is often not what we need, then we can pull the chart package, and then modify the parameters before executing.

  • Pull down the chart package, decompress it, and 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.yamlfile, but it will not be modified here.
  • Then execute the modified values.yamlfile, 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, just talk about the basic use of helm.
In the future, I will write the use of charts, and create charts and other content by myself.

Guess you like

Origin blog.csdn.net/qq_42527269/article/details/123027203