K8s - 3 core concept - 15 Helm

K8s - Catalog

1, kubernetes core technology Helm

1. Helm introduction

Application objects on K8S are composed of specific resource descriptions, including deployment, service, etc. They are saved in their own files or written to a configuration file. Then kubectl apply – f is deployed. If the application consists of only one or several such services, the above deployment method is sufficient. For a complex application, there will be many resource description files similar to the above, such as micro service architecture application. There may be as many as ten or dozens of services constituting the application. If there is a need to update or rollback the application, it may be necessary to modify and maintain a large number of resource files involved, and this way of organizing and managing the application is insufficient. Moreover, due to the lack of version management and control of published applications, the application maintenance and update on Kubernetes face many challenges, mainly facing the following problems:

  • How to manage these services as a whole;
  • How to reuse these resource files efficiently;
  • Application level version management is not supported.

2. Helm introduction

Helm is a package management tool of kubernetes, just like the package manager under Linux, such as yum/apt, which can easily deploy the previously packaged yaml file to kubernetes.

Helm has three important concepts:

  • helm: a command-line client tool, which is mainly used for the creation, packaging, publishing and management of Kubernetes application chart;
  • Chart: application description, a collection of files used to describe k8s resources;
  • Release: the deployment entity based on chart. After a chart is run by Helm, a corresponding release will be generated. A real running resource object will be created in k8s.

3. Helm v3 change

On November 13, 2019, Helm team released the first stable version of Helm v3.

The main changes of this version are as follows:

  • Architecture changes:

    1. The most obvious change is the deletion of Tiller.

    2. Release names can be reused in different namespaces.

    3. It supports pushing Chart to Docker image warehouse.

    4. Verify chart values using JSONSchema.

    5. other.

4. Helm client

4.1 deploy helm client

Helm client download address:
https://github.com/helm/helm/releases

Unzip and move to / usr/bin / directory.

wget https://get.helm.sh/helm-vv3.2.1-linux-amd64.tar.gz
tar zxvf helm-v3.2.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/bin/

helm common commands

commanddescribe
dependencyManage chart dependencies
getDownload a release. Available subcommands: all, hooks, manifest, notes, values
historyGet release history
installInstall a chart
listList release s
packagePackage the chart directory into the chart archive file
pullDownload chart from the remote warehouse and unzip it to the local # helm pull stable/mysql – untar
repoAdd, list, remove, update and index chart warehouses. Available subcommands: add, index, list, remove, update
rollbackRollback from previous version
searchSearch chart by keyword. Available subcommands: hub, repo
showView chart details. Available subcommands: all, chart, readme, values
statusDisplays the status of the named version
templateLocal rendering template
uninstallUninstall a release
upgradeUpdate a release
versionView the helm client version

4.2 configure domestic chart warehouse

  • Microsoft warehouse( http://mirror.azure.cn/kubernetes/charts/ )This warehouse is recommended. Basically, some charts on the official website are available here.
  • Alibaba cloud warehouse( https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts )
  • Official warehouse( https://hub.kubeapps.com/charts/incubator )The official chart warehouse is a little difficult to use in China.

Add repository

helm repo add stable http://mirror.azure.cn/kubernetes/charts
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update

View configured repositories

helm repo list 
helm search repo stable

Delete repository

helm repo remove aliyun

5. helm basic use

Three commands are mainly introduced:

  • chart install
  • chart upgrade
  • chart rollback

5.1 deploying an application using chart

Find chart

helm search repo weave
NAME               CHART VERSION APP VERSION DESCRIPTION
aliyun/weave-cloud 0.1.2                     Weave Cloud is a add-on to Kubernetes which pro...
aliyun/weave-scope 0.9.21.6.5                A Helm chart for the Weave Scope cluster visual...
stable/weave-cloud 0.3.71.4.0                Weave Cloud is a add-on to Kubernetes cluster visual...
stable/weave-scope 0.3.71.4.0                A Helm chart for the Weave Scope cluster visual...

View chrt information

helm show chart stable/mysql

Installation package

helm install ui stable/weave-scope

View publishing status

helm list
NAME NAMESPACE REVISION UPDATED                              STATUS   CHART APP                VERSION
ui   default   1        2020-05-2817:45:01.696109626+0800CST deployed weave-scope-1.1.101.12.0
helm status ui
NAME: ui
LAST DEPLOYED: Thu May 2817:45:012020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by using kubectl port-forward:                                                 kubectl -n default port-forward $(kubectl -n default get endpoints \        ui-weave-scope -o jsonpath=' {.subsets[0].addresses[0].targetRef.name}')     8080:4040                                                                   
then browsing to http://localhost:8080/.                                    
For more details on using Weave Scope, see the Weave Scope documentation:   
https://www.weave.works/docs/scope/latest/introducing/
#Modify the service Type: NodePort to access the ui

5.2 custom chart configuration options before installation

The custom option is because not all chart s can run successfully according to the default configuration. Some environment dependencies may be required, such as PV.

Therefore, we need to customize the chart configuration option. There are two methods to transfer configuration data during installation:

  • – values (or - f): Specifies the YAML file with overrides. This can be specified multiple times, and the rightmost file takes precedence;
  • – set: specify an override on the command line. If both are used, – set has high priority.

– values use
First write the modified variable to a file.

helm show values stable/mysql
cat config.yaml
persistence:
  enabled: true
  storageClass: "managed-nfs-storage"
  accessMode: ReadWriteOnce
  size: 8Gi
  mysqlUser: "k8s"
  mysqlPassword: "123456"
  mysqlDatabase: "k8s
helm install db -f config.yaml stable/mysql
kubectl get pods
NAME                      READY STATUS  RESTARTS AGE
db-mysql-57485b68dc-4xjhv 1/1   Running 0        8m51s 
kubectl run -it db-client --rm --restart=Never --image=mysql:5.7 -- bash
If you don't see a command prompt, try pressing enter.
mysql -hdb-mysql -uk8s -p123456
mysql: [Warning] Using a password on the command line
interface can be insecure. Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation
and/or its affiliates. Other names may be trademarks of
their respective owners.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement. 
show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| k8s                |
+--------------------+

A default MySQL user k8s with a name will be created and granted access to the newly created k8s database, but all remaining defaults for the chart will be accepted.

Command line override variables:

helm install db --set persistence.storageClass="managed-nfs-storage" stable/mysql

You can also download the chart package to view the details:

helm pull stable/mysql --untar

values yaml and set use:

The helm install command can be installed from multiple sources:

  • chart repository;
  • Local chart Archive (helm install foo-0.1.1.tgz);
  • Local chart Archive (helm install foo-0.1.1.tgz);
  • Full URL (helm install) https://example.com/charts/foo-1.2.3.tgz ).

6. Build a Helm Chart

6.1 chart template

6.2 commissioning

6.3 built in objects

6.4 Values

6.5 upgrade, rollback and deletion

6.6 pipes and functions

7. Process control

7.1 if

7.2 range

7.3 with

7.4 variables

8. Develop your own chart

  1. Create a template first.
  2. Modify chart yaml,Values.yaml, add common variables.
  3. Create the yaml file required for deploying the image in the templates directory, and the variable references the frequently changing fields in yaml.

Keywords: Kubernetes

Added by atravotum on Sat, 19 Feb 2022 14:09:10 +0200