preface

For example, Java has Maven/Gradle, Python has PIP, NodeJS has NPM/YARN, etc., and K8S also has its package management tool -helm. Using HELM makes it easier to publish applications to K8S clusters.

The environment

The host name ip role
mldong01 192.168.0.245 master
mldong02 192.168.0.54 node01
mldong03 192.168.0.22 node02

Three hosts are HUAWEI ECS, CentOS Linux release 7.6.1810 (Core)

Install the Helm

Here is the latest version of Helm3.4.2,Linux AMD64 installed

Github.com/helm/helm/r…

Note: Kubectl must be installed before installation. In fact, k8S cluster installed with RKE already has helm installed by default. Since I’m using it on another non-cluster node, I have to install the tools myself.

#Downloading binary packagesWget HTTP: / / https://get.helm.sh/helm-v3.4.2-linux-amd64.tar.gz#Unpack theTar - ZXVF helm - v3.4.2 - Linux - amd64. Tar. Gz#Copy to the desired directory
 mv linux-amd64/helm /usr/local/bin/helm
#Verify that the installation is successful
 helm -h
Copy the code

Common Helm Commands

Add common chart sources

[root@mldong ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
[root@mldong ~]# helm repo add aliyuncs https://apphub.aliyuncs.com
"aliyuncs" has been added to your repositories
Copy the code

View chart list

[root@mldong ~]# helm repo list
NAME            URL                               
bitnami         https://charts.bitnami.com/bitnami
aliyuncs        https://apphub.aliyuncs.com       

Copy the code

Search local Chart

[root@mldong01 ~]# helm Search repo nginx NAME CHART VERSION APP VERSION DESCRIPTION Aliyuncs /nginx 5.1.5 1.16.1 CHART For the nginx server aliyuncs/nginx-ingress 1.30.3 0.28.0 An nginx ingress controller that uses ConfigMap... Nginx-ingress controller 5.3.4 0.29.0 Chart for the nginx Ingress controller Aliyuncs/nginx-Ingress controller 5.3.4 0.29.0 Chart for the nginx Ingress Controller Aliyuncs/nginx-Ingress controller 0.3.1 Chart Nginx-1.0.0 nginx-1.10.3_php-7.0 Chart for the nginx PHP server Nginx 8.2.3 1.19.6 Chart for the Nginx server Bitnami /nginx-ingress-controller 7.0.6 0.42.0 Chart for the Nginx server Ingress Controller Bitnami/Kong 3.1.0 2.2.1 Kong is a Scalable, Open Source API Layer (aka...Copy the code

Download the Chart package locally

#Create a directory
mkdir -p /java_projects/k8s/helm-charts
#Enter the directory
cd /java_projects/k8s/helm-charts
#Download chart package[root@mldong helm-charts]# helm Pull Aliyuncs /nginx --untar [root@mldong helm-charts]# Tree-L 2 Nginx/Nginx / ├── Chart. Yaml ├ ─ ─ ci │ └ ─ ─ values - with - ingress - metrics - and - serverblock. Yaml ├ ─ ─ the README. Md ├ ─ ─ templates │ ├ ─ ─ Deployment. Yaml │ ├ ─ ─ _helpers. TPL │ ├ ─ ─ ingress. The yaml │ ├ ─ ─ the TXT │ ├ ─ ─ server - block - configmap. Yaml │ ├ ─ ─ Servicemonitor. Yaml │ ├ ─ ─ SVC. Yaml │ └ ─ ─ the TLS - secrets. Yaml ├ ─ ─ values. The schema. The json └ ─ ─ values. The yaml 2 directories and filesCopy the code

If the tree tool is not available, install it first

yum install tree 
Copy the code

Helm Usage Tips

Using nginx as an example, share a few tips

Publish the service according to the default configuration

#release
helm install nginx aliyuncs/nginx
#Viewing health
kubectl get svc -w nginx
#delete
helm delete nginx
Copy the code

Specify the namespace publishing service

#Create a namespace - if it does not exist
kubectl create ns nginx-test
#release
helm install nginx aliyuncs/nginx -n nginx-test
#Viewing health
kubectl get svc -n nginx-test -w nginx
#delete
helm delete nginx -n nginx-test
#Deleting a namespace
kubectl delete ns nginx-test
Copy the code

View chart source code

You can download it locally using the pull method described above, which is not described here.

#Chart basic information
helm show chart aliyuncs/nginx
#Focus on Sources, usually a Github address, and then go to the browser, like this one
Copy the code

Of course, this is not very friendly, there is no direct chart address, you need to find it yourself

And then below that is the template

Then here are the configuration instructions

How to view the configuration file

The above one actually contains the way to view the configuration, here is another way to use the command to view

helm show values aliyuncs/nginx
Copy the code

Modify configuration publishing in the command line

Since I already know part of the configuration, I will enable ingress

#Create a namespace - if it does not exist
kubectl create ns nginx-test
#release
helm install nginx aliyuncs/nginx -n nginx-test --set ingress.enabled=true --set ingress.hostname=a.mldong.com
#Viewing health
kubectl get svc -n nginx-test -w nginx
#Check the ingress
kubectl get ingress -n nginx-test
#View the ingress profile
kubectl get ingress -n nginx-test -o yaml
#delete
helm delete nginx -n nginx-test
#Deleting a namespace
kubectl delete ns nginx-test
Copy the code

Corresponding logic on the source code

Publish using external configuration files

This is recommended because –set supports a limited number of data types

#Create a configuration file first
cat <<EOF >  nginx-values.yaml
ingress: 
  enabled: true
  hostname: a.mldong.com
EOF
Copy the code
#Create a namespace - if it does not exist
kubectl create ns nginx-test
#release
helm install nginx aliyuncs/nginx -n nginx-test -f nginx-values.yaml
#Viewing health
kubectl get svc -n nginx-test -w nginx
#Check the ingress
kubectl get ingress -n nginx-test
#View the ingress profile
kubectl get ingress -n nginx-test -o yaml
#delete
helm delete nginx -n nginx-test
#Deleting a namespace
kubectl delete ns nginx-test
Copy the code

Configuration changes

#Create a namespace - if it does not exist
kubectl create ns nginx-test
#release
helm install nginx aliyuncs/nginx -n nginx-test
#Viewing health
kubectl get svc -n nginx-test -w nginx
#Check the ingress
kubectl get ingress -n nginx-test
#Update configuration publishing
helm upgrade nginx aliyuncs/nginx -n nginx-test --set ingress.enabled=true --set ingress.hostname=a.mldong.com
#Check out ingress again
kubectl get ingress -n nginx-test
#delete
helm delete nginx -n nginx-test
#Deleting a namespace
kubectl delete ns nginx-test
Copy the code

Enable the debug mode

#Create a namespace - if it does not exist
kubectl create ns nginx-test
#release
helm install nginx aliyuncs/nginx -n nginx-test --debug
#Viewing health
kubectl get svc -n nginx-test -w nginx
#Check the ingress
kubectl get ingress -n nginx-test
#View the ingress profile
kubectl get ingress -n nginx-test -o yaml
#delete
helm delete nginx -n nginx-test
#Deleting a namespace
kubectl delete ns nginx-test
Copy the code

— Dry-run parameter is used

This parameter does not run, but is used with –debug

#Create a namespace - if it does not exist
kubectl create ns nginx-test
#release
helm install nginx aliyuncs/nginx -n nginx-test --dry-run
Copy the code

summary

This article has just covered some of the most common examples of Helm. It takes practice to become proficient in using Helm. It is recommended to have a look at chart source templates, most of which are elegantly designed and well considered. In retrospect, the continuous integration template for my introductory article was a little too weak. But for starters, too much configuration isn’t suitable.

Related articles

K8s Intermediate – Installing a K8S cluster using RKE

K8s Intermediate – Cert-Manager +Let’s Encrypt Automatic certificate issuing

K8s Intermediate -Helm Install nfs-client-provisioner