Helm, as a package management tool of Kubernetes system, has gradually become the standard for application distribution. In.NET development, it can be understood as similar to NuGet package. To recall from previous articles, the deployment of a single service in Kubernetes sometimes involves multiple resource types, such as: Deployemet, Service, Ingress, PVC, ConfigMap, Secret, etc., and through Helm, you can package the Service related resources into a chart for version management based on chart. Simplify versioning, packaging, publishing, deleting, and updating of Kubernetes deployment applications.

The following is the architecture diagram of Helm 3. Create chart through Helm Client, and then create related resources based on chart in Kubernetes. Meanwhile, Chart can be saved in chart warehouse for chart package management and sharing.

Installing and configuring the Helm

Installing the Helm 3 is easy with a few steps, and I use Binary Releases. After the installation is complete, the chart warehouse source should be added, which can be searched and installed only when it is available. Add the azure and Aliyun repository sources first:

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
Copy the code

After the above configuration, you can use helm Search repo XXXX to search the related chart package for installation (similar to Docker Search). Such as:

Build repo

Here, I will use Harbor to save Helm Chart, download the latest release version of Harbor-Offline – Installer, and make relevant modifications to harbor.yml after decompression. The main configurations are as follows (if HTTPS is not used, Note the HTTPS related fields in the configuration file) :

Table: Absolute_URL: enabledCopy the code

After the first installation, execute the following command (stop or start execution. / docker – compose start | stop) :

./install.sh --with-clair --with-chartmuseum
Copy the code

After successful installation, go to http://192.168.124.9:8888, create a project called charts as used in the chart of the warehouse.

Added in the Helm self-built repo, http://192.168.124.9:8888/chartrepo/charts, because the level of charts project is private, so when added to the incoming user name and password, as follows:

Helm repo add harbor http://192.168.124.9:8888/chartrepo/charts - username = admin - password = Harbor12345 helm repo updateCopy the code

Create a Chart

Run helm create k8sdemo to create chart named k8sdemo, and a batch of files are generated. The file structure is shown in the following figure. Some files are familiar to us, for example: Yaml, ingress.yaml, service.yaml:

├ ─ ─ charts ├ ─ ─ Chart. Yaml ├ ─ ─ templates │ ├ ─ ─ deployment. The yaml │ ├ ─ ─ _helpers. TPL │ ├ ─ ─ hpa. The yaml │ ├ ─ ─ ingress. The yaml │ ├ ─ ─ │ ├─ ├─ ├─ test.txt │ ├─ ├─ test.txt │ ├─ ├─ test.txt │ ├─ ├.txt │ ├─ ├─ test.txtCopy the code
  • Charts: Stores all subcharts that the chart depends on;
  • Chart.yaml: Definition of basic information, such as name, version, description, etc.
  • templates: Stores template files._helpers.tplDefine variables,NOTES.txtComment files, yamL files are templates for defining each resource type,testsBelow are the related test templates;
  • values.yaml: Defines constants that need to be used in the template. If a constant needs to be processed twice, it needs to be processed in the_helpers.tplThrough variables, such as:
{{- define "k8sdemo.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
Copy the code

The templates folder contains a lot of references to constants and variables, so the syntax is easy to understand

K8sdemo Chart creation mainly includes the following 3 file adjustments:

Values. Yaml is modified as follows: Create 3 pods, use beckjin/ K8sdemo :1.0.0 for mirroring, use NodePort for service, external port 31000, and keep other default values:

ReplicaCount: 3 image: repository: beckjin/k8sdemo pullPolicy: IfNotPresent Tag: "1.0.0" service: type: NodePort port: 80 nodePort: 31000Copy the code

Templates/deployment. Yaml major changes health check the configuration of the default is/routing, here to/weatherforecast, as follows:

livenessProbe:
  httpGet:
    path: /weatherforecast
    port: http
readinessProbe:
  httpGet:
    path: /weatherforecast
    port: http
Copy the code

Templates /service.yaml mainly changes the nodePort field, referencing the constant values.service. nodePort as follows:

spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      nodePort: {{ .Values.service.nodePort }}
      protocol: TCP
      name: http
Copy the code

Yaml, ingress.yaml, and ServiceAccount. yaml are all enabled with switches and are disabled by default. Finally, you can check the syntax at helm Lint K8sdemo /, and if there is no problem, you can package it as chart directly.

Pushed to the repo

Chart push here will be accomplished by using the helm-push plug-in, which is used to push the created Chart package to the remote Chart repository. Due to network problems, it is suggested that direct download version of the corresponding system release package, uploaded to the Helm of the plug-in directory, under Linux is: the/root/local/share/Helm/plugins /.

└ ─ ─ helm - push ├ ─ ─ bin │ └ ─ ─ helmpush ├ ─ ─ helm - push_0. 8.1 _linux_amd64. Tar. Gz ├ ─ ─ LICENSE └ ─ ─ the plugin. The yamlCopy the code

Package the k8sdemo folder to generate k8sDemo-1.0.0.tgz

helm package k8sdemo/
Copy the code

Pushed to the harbor

Helm push k8sdemo - 1.0.0. TGZ harborCopy the code

After successful push, the corresponding Chart package will appear under Helm Charts of the Charts project:

Install the Chart

Before installing the helm repo, run the helm search repo k8sdemo command to view the result. Otherwise, you cannot obtain the latest information.

Run helm install k8sdemo harbor/k8sdemo to install the harbor. The following information is displayed, which is defined in notes.txt. Kubectl get Services (kubectl get Services, kubectl Get Services, Kubectl Get Services)

upgrade

If Chart needs to be upgraded, you can modify the version field in Chart.yaml, repackage and push it, and then HELM Repo Update updates chart warehouse, Finally, run helm Upgrade K8sdemo Harbor /k8sdemo to upgrade it.

The rollback

Run helm history k8sdemo to view the historical version and run helm rollback k8sdemo to rollback the previous version.