Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Helm in kubernetes

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to achieve Helm in kubernetes, which is very detailed and has a certain reference value. Interested friends must read it!

One: brief introduction

It is not easy to deploy containerized on Kubernetes. Usually, you need to study the operation requirements and environment variables of Docker image, and customize storage, network and other devices for these containers. Finally, you can design and write Deployment,Configmap,Service and Ingress and other related yaml configuration files, and then submit them to Kubernetes for deployment. These complex processes will gradually be implemented by Helm application package management tools.

Helm is a project incubated and managed by CNCF to define, install and update complex applications that need to be deployed on Kubernetes. Helm describes the information of application software in the way of Chart, so it is convenient to create, version, share and publish complex application software.

Second: the main concepts of Helm

1. Chart: it is a Helm-managed installation package that contains the installation package resources that need to be deployed. Similar to the rpm file in yum. Each Chart consists of two parts: the basic description file of the package, Chart.yaml, is placed in the templates directory with one or more Kubernetes manifest file templates.

2.Release: an instance of Chart running on a Kubernetes cluster. A Chart can be installed multiple times on the same cluster. For example, a MySQL Chart, if you want to run two MySQL databases on the server, you can basically install the Chart twice. Each installation generates a new Release with a separate Release name.

3.Repository: a repository for storing and sharing Chart.

Third: installation of Helm

1.Helm consists of two parts, the client helm and the service tiller.

two。 Installation of client helm

Curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh

Chmod 755 get_helm.sh

. / get_helm.sh

In the process of executing the get_helm.sh script, if you cannot get the helm installation package, you can download the latest stable version of the installation package to the current directory through https://github.com/kubernetes/helm/releases in advance, and then execute the get_helm.sh file. Helm-v2.9.1-linux-amd64.tar.gz is used here.

3. Client tiller installation

Create serviceaccount and clusterrolebinding

Kubectl create serviceaccount-namespace kube-system tiller

Kubectl create clusterrolebinding tiller-cluster-rule-clusterrole=cluster-admin-serviceaccount=kube-system:tiller

Install tiller

Helm init-I registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1

Set serviceaccount for tiller

Kubectl patch deploy-- namespace kube-system tiller-deploy-p'{"spec": {"template": {"spec": {"serviceAccount": "tiller"}'

Check whether the installation is successful

Kubectl-n kube-system get pods | grep tiller

Tiller-deploy-59c7578f9b-qqwpm 1/1 Running 0 17h

Helm version

Client: & version.Version {SemVer: "v2.9.1", GitCommit: "20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState: "clean"}

Server: & version.Version {SemVer: "v2.9.1", GitCommit: "20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState: "clean"}

IV: the use of Helm

1.helm search: search for available Chart

After Helm initialization is complete, the default configuration is to use the official Kubernetes Chart repository. The official warehouse contains a large number of organized and continuously maintained Chart, which is usually named stable.

You can use the helm inspect command to view the details of Chart.

2.helm create: create a chart

Helm create nginx

The deployment.yaml in the templates directory is the yaml file for deploying the application. The expanded part of the parenthesis is Go template, in which the Values is in values.yaml? Is defined in the.

The chart that this chart depends on in the a.charts directory is currently empty

B.Chart.yaml this yaml file is used to describe the basic information of Chart, such as name version, etc.

C.templates is the Kubernetes manifest file template directory, and the template generates the Kubernetes manifest file using the values configured by chart. The Go language template syntax used by the template file

D.templates/NOTES.txt plain text file in which you can fill in the instructions for using chart

E.value.yaml is the default value for chart configuration

3. Helm install-dry-run-debug. /: verify the template and configuration

[debug] Created tunnel using local port: '44785'

[debug] SERVER: "127.0.0.1 purl 44785"

[debug] Original chart version: ""

[debug] CHART PATH: / root/helm/nginx

NAME: listless-blackbird

REVISION: 1

RELEASED: Wed Jun 6 10:00:49 2018

CHART: nginx-0.1.0

USER-SUPPLIED VALUES:

{}

COMPUTED VALUES:

Affinity: {}

Image:

PullPolicy: IfNotPresent

Repository: nginx

Tag: stable

Ingress:

Annotations: {}

Enabled: false

Hosts:

-chart-example.local

Path: /

Tls: []

NodeSelector: {}

ReplicaCount: 1

Resources: {}

Service:

Port: 80

Type: ClusterIP

Tolerations: []

HOOKS:

MANIFEST:

-

# Source: nginx/templates/service.yaml

ApiVersion: v1

Kind: Service

Metadata:

Name: listless-blackbird-nginx

Labels:

App: nginx

Chart: nginx-0.1.0

Release: listless-blackbird

Heritage: Tiller

Spec:

Type: ClusterIP

Ports:

-port: 80

TargetPort: http

Protocol: TCP

Name: http

Selector:

App: nginx

Release: listless-blackbird

-

# Source: nginx/templates/deployment.yaml

ApiVersion: apps/v1beta2

Kind: Deployment

Metadata:

Name: listless-blackbird-nginx

Labels:

App: nginx

Chart: nginx-0.1.0

Release: listless-blackbird

Heritage: Tiller

Spec:

Replicas: 1

Selector:

MatchLabels:

App: nginx

Release: listless-blackbird

Template:

Metadata:

Labels:

App: nginx

Release: listless-blackbird

Spec:

Containers:

-name: nginx

Image: "nginx:stable"

ImagePullPolicy: IfNotPresent

Ports:

-name: http

ContainerPort: 80

Protocol: TCP

LivenessProbe:

HttpGet:

Path: /

Port: http

ReadinessProbe:

HttpGet:

Path: /

Port: http

Resources:

{}

4.helm install: installing Chart

During installation, the Helm client outputs some useful information, such as the status of Release, as well as additional configuration steps. During the helm install process, you can use the helm status command to track the release status.

5. Customize Chart configuration

A.--values or-f: use the yaml configuration file for parameter configuration. Multiple files can be configured, and the last one takes precedence. Duplicate value in multiple files will be overwritten, and different value will be superimposed.

B.--set: setting parameters directly on the command line

For example:

Helm install stable/mariadb-f config.yaml-f config2.yaml

Helm install stable/mariadb-set mariadbDatabase=firstdb,mariadbRootPassword=abcdefg

6.helm upgrade and helm rollback: applied updates or rollback

Helm upgrade uses the update information provided by the user to update the Release. Because Kubernetes Chart may have large-scale or relatively complex relationships, helm will try to update with minimal impact, updating only the content that has changed from the previous release.

7.helm delete: delete a Release

8.helm repo: use of warehouses

A. helm repo list: list all warehouses

NAME URL

Stable https://kubernetes-charts.storage.googleapis.com

Local http://127.0.0.1:8879/charts

B. helm repo add: add a warehouse

C.helm repo update: update Chart information in the repository

9. Quickly make custom Chart

As with other software development processes, a quick way to make a simple Chart is to copy and modify it from other projects. For example, to simply rewrite the Chart of the previous MariaDB to use the local private image repository, you can follow the following steps:

a. Download Chart: use the helm fetch stable/mariadb command to download the Chart package

b. Edit Chart

c. After decompressing with tar, rename the directory to mymariadb

d. Modify deployment.yaml in templates

e. Change the version number in Chart.yaml to 0.1.1 name to mymariadb

f. Use helm package mymariadb to package chart and generate a compressed package called mymariadb-0.11.tgz

g. Install chart installs the newly generated Chart into the cluster through the helm install mymariadb-0.1.1.tgz command.

10. Set up a private Repository

Chart warehouse is mainly composed of Chart compression package and index files, and provides services through HTTP/HTTPS.

Create an index through helm repo index

These are all the contents of the article "how to achieve Helm in kubernetes". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report