当前位置:网站首页>Install software on kubernetes cluster using helm 3 package manager
Install software on kubernetes cluster using helm 3 package manager
2022-07-24 23:56:00 【A fishy summer】
Introduce
Helm yes Kubernetes Package manager , It allows developers and network administrators to work more easily in Kubernetes Configure and deploy applications on the cluster .
Helm The bag is called charts, They contain resource definition templates , These templates can deploy and configure a given application , Users only need to pay the least work .
Use templates , You can manage charts by passing in variable definitions 、 Its settings and behavior , Without modifying the actual chart .Helm Automatically manage custom resource definitions and modifications to deployed definitions . Deployed with possible customization chart be called Release .
In this tutorial , You will set Helm 3 And learn how to install 、 upgrade 、 Rollback and manage charts and versions . You will also learn to create and package your own charts , And setting up the chart repository , Which hosts charts that you can install immediately .
The first 0 Step - establish k8s Environmental Science
This tutorial uses CSDN Development cloud provides k8s learning environment , One click creates k8s Environmental Science .CSDN Developing the cloud k8s The learning environment is paid by the hour , Only per hour 0.1 element . After learning, you can release the host resources and the billing will stop .
Click here to have k8s Environmental Science .
You can also use other methods to create your own k8s colony .
Click on 【 Buy now 】 after , In a few minutes you can have your own k8s colony .
- Installed on the local computer
kubectlCommand line tools , Configured to connect to your cluster .kubectlYou can find it in the official documents Read more about installation in .
You can also use ssh Terminal tool login k8s Cluster host , Perform the following operations in the server terminal
You can use the following command to test your connectivity :
kubectl cluster-info
If you don't receive any errors , Then you are connected to the cluster . If you use to access multiple clusters kubectl, Please make sure to verify that you have selected the correct cluster context by running the following command :
kubectl config get-contexts
The above command lists the available configurations :
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* default default default
ad locum , asterisk ( *) Indicates that we are connected to default colony . To switch clusters , Please run :
kubectl config use-context <context-name>
When you connect to the correct cluster , Continue with step 1 Start installation Helm.
The first 1 Step — install Helm 3
In this section , You will use the official shell Script install Helm 3 .
First switch to /tmp, You will run the following command to store the installation script :
cd /tmp
Use the following command to download the script :
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
You can use a text editor to view get_helm.sh Content to ensure its security .
Set its permission to be executable through the following command :
chmod +x get_helm.sh
Last , Run it to install Helm 3:
./get_helm.sh
You will receive output similar to the following :
Downloading https://get.helm.sh/helm-v3.9.0-linux-amd64.tar.gz
Verifying checksum... Done.
Preparing to install helm into /usr/local/bin
helm installed into /usr/local/bin/helm
Your machine is equipped with Helm 3. Now you will understand charts Repositories and how to use them
The first 2 Step — Set up chart repository
Helm charts Stored in charts Repository , Anyone can trust . By default ,Helm 3 No repository is preconfigured . The previous version of Helm Including a central charts The repository ; However ,Helm 3 The design of evolves into charts Developers manage their own repositories , Thus allowing more freedom and faster release . This means for everyone you want to use chart, You need to make sure that the managed repository is added to your Helm Installing .
To help you find the right repository , You can use ArtifactHub.io , This is a result of CNCF Managed open source website , Yes Helm charts And its repository . It also tracks other CNCF Popular and useful charts used in the project , So it's different from stable The previous version of Helm The repository used . For common projects , for example Nginx ingresses or monitoring Tools , It's a good choice .
You can search the homepage to install chart. Search for nginx All... Related to it will be displayed chart.

Search for ingress-nginx To find it in your results . Select by Kubernetes Community version of team management , Click to access its page .

Every chart There is a detailed description of its functions , And add its repository to your installation and installation diagram . without , You can still press... On the right side of the page INSTALL Button to get the necessary commands .

Every chart There is a detailed description of its functions , And add its repository to your installation and installation diagram .
without , You can still press... On the right side of the page INSTALL Button to get the necessary commands .

You can copy it by clicking the blue button next to the command . Do this for the first command , Then run it :
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
To add a repository to Helm, Please run helm repo add. The parameters it accepts are the name of the repository and its location .
The output will be :
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
"ingress-nginx" has been added to your repositories
The warning is because k8s The configuration file of is not secure , Users in the same user group and other users can read this file
Solve this alarm , Modify the permissions :
chmod g-rw ~/.kube/config
chmod o-r ~/.kube/config
function helm version The alarm information is gone
When you add a new repo when , You need to make Helm Know what it contains :
helm repo update
You will receive the following output , Indicates that the update was successful :
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "ingress-nginx" chart repository
Update Complete. ⎈Happy Helming!⎈
In this step , You've got it ArtifactHub And what it provides . You also want to Helm Installation adds a new repository . In the next step , You will install Helm chart.
The first 3 Step — install Helm Chart
In the last section , You have ingress-nginx chart Added repository . You now install it into your cluster .
Every chart There are configuration variables , You can set these variables to modify their behavior . These variables are stored in a file named , This document values.yaml Is part of the chart . Unless you have downloaded the chart to your computer , Otherwise, you must run the following command to view it :
helm show values <chart_name>
To display the Available variables for ingress-nginx, Please replace chart_name:
helm show values ingress-nginx/ingress-nginx
Will output ingress-nginx Of values.yaml Content , It's a lot of stuff
To install chart, You can use helm install command , The format is as follows :
helm install <release_name> <repository/chart_name>
release_name yes chart Deployment instance *,* I'll call it here ingress-nginx.
This command will use the default value of the variable to install the chart into your cluster . If you want to modify some of them , You can use the following methods to pass in new variable values --set:
helm install ingress-nginx/ingress-nginx --set variable_name=variable_value
You can repeat any as needed --set Quantity variable . Because we won't customize it now , So install it as is by running :
helm install ingress-nginx ingress-nginx/ingress-nginx
The output will be similar to the following :
NAME: ingress-nginx
LAST DEPLOYED: Sat Jul 9 16:02:19 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The ingress-nginx controller has been installed.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl --namespace default get services -o wide -w ingress-nginx-controller'
An example Ingress that makes use of the controller:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example
namespace: foo
spec:
ingressClassName: nginx
rules:
- host: www.example.com
http:
paths:
- pathType: Prefix
backend:
service:
name: exampleService
port:
number: 80
path: /
# This section is only required if TLS is to be enabled for the Ingress
tls:
- hosts:
- www.example.com
secretName: example-tls
If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:
apiVersion: v1
kind: Secret
metadata:
name: example-tls
namespace: foo
data:
tls.crt: <base64 encoded cert>
tls.key: <base64 encoded key>
type: kubernetes.io/tls
Please note that ,NAME Corresponding to the version name you specified .Helm It also lists common information , For example, publish the state and the namespace to deploy it . The NOTES Partial cause chart But different , It usually contains a quick start guide or a warning about some common pitfalls when using chart resources . ad locum , It indicates that a load balancer is being created , And it may take some time to complete .
To check deployed chart, Please use helm list:
helm list
You'll find that ingress-nginx It is the only one deployed at present chart:
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
ingress-nginx default 1 2022-07-09 07:25:32.861880478 +0800 CST deployed ingress-nginx-4.1.4 1.2.1
You can find its services in the cluster by running the following command :
kubectl get services
The output will be similar :
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.245.211.81 116.196.125.86 80:30704/TCP,443:30700/TCP 7m19s
ingress-nginx-controller-admission ClusterIP 10.245.50.17 <none> 443/TCP 7m19s
kubernetes ClusterIP 10.245.0.1 <none> 443/TCP 83m
Now you have deployed the release to the cluster , You will modify its configuration at deployment .
The first 4 Step — Upgraded version
After deployment and release , You don't need to dismantle it and completely redeploy it when you need to change its configuration . You can use this helm upgrade The command uses the new version chart Upgrade release , Or set new settings .
The ingress-nginx chart It's public controller.replicaCount Control deployed controller pod Quantity variable . By default , It's set to 1, You can list the available pod Check it out. :
kubectl get pods
You will find that there is only one :
NAME READY STATUS RESTARTS AGE
ingress-nginx-controller-7fc74cf778-kjtst 1/1 Running 0 12m
If you want to deploy more instances to achieve high availability ( for example , Three ), You can run upgrade Release and set the variable to 3:
helm upgrade ingress-nginx ingress-nginx/ingress-nginx --set controller.replicaCount=3 --reuse-values
You also introduced --reuse-values, It indicates Helm Base your changes on the deployed version , Keep the previous configuration .
In the output ,Helm The version will be modified to indicate that the version has been upgraded :
NAME: ingress-nginx
LAST DEPLOYED: Sat Jul 9 16:02:19 2022
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
...
You can list available by running pod:
kubectl get pods
You will find three listed pod, Instead of a :
NAME READY STATUS RESTARTS AGE
ingress-nginx-controller-7c54d79885-6sb8z 1/1 Running 0 21h
ingress-nginx-controller-7c54d79885-qrwf6 1/1 Running 0 27h
ingress-nginx-controller-7c54d79885-fzrc8 1/1 Running 0 21h
Next , You will rollback the changes and completely delete the version .
The first 5 Step — Rollback and delete version
When you upgrade When it was released , Its revision number will be increased . In the internal ,Helm Store all revisions of the version , Allows you to return to previous revisions when needed .
To put pod The number of is restored to only one , You can helm upgrade Run again and set the quantity manually , Because this is a small change . however , When using chart when , Manual restore is not elegant .
To rollback the version , Please use helm rollback:
helm rollback <release_name> <release_revision>
You can use it ingress-nginx Restore your changes by rolling back to the revision 1:
helm rollback ingress-nginx 1
You will receive the following output , Indicates successful operation :
Rollback was a success! Happy Helming!
You can check the current version by listing the published version :
helm list
You will find that the revised version is 3, instead of 1:
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
ingress-nginx default 3 2022-07-10 21:53:57.94583986 +0800 CST deployed ingress-nginx-4.1.4 1.2.1
Helm Change each ( Including rollback ) As a new revision to the release . You can check the deployment by running the following command pod To check the revision 3 Is it equal to the first :
kubectl get pods
You will find that there is only one :
NAME READY STATUS RESTARTS AGE
ingress-nginx-controller-7c54d79885-6sb8z 1/1 Running 0 22h
To delete a version and all its revisions , You can use helm delete:
helm delete <release_name>
Because you no longer need it , please ingress-nginx Delete by running the following command :
helm delete ingress-nginx
The output will be :
release "ingress-nginx" uninstalled
You can list the versions to check if there are no :
helm list
The output table will have no rows :
NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
Now this version has been deleted , You can reuse its name in future deployments .
The first 6 Step - Create custom charts
In this optional step , You will learn how to create customizations chart、 Where to place the resource definition and how to package it for further distribution .
You will create one called The new chart example-chart. Run the following command to create it :
helm create example-chart
This will create a file named example-chart New directories for the following files and structures :
example-chart/
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
The resources you will install on the target cluster , The definition is located in this templates Directory .
Helm The default deployment created is a Nginx Entrance controller . Although their file extensions are YAML, But they use Go The template syntax of is customizable through the public variables you can pass in . You can run the following command to display service.yaml Content :
cat example-chart/templates/service.yaml
You will find that it supports template instructions , Enclosed in double brackets are template syntax
apiVersion: v1
kind: Service
metadata:
name: {
{
include "example-chart.fullname" . }}
labels:
{
{
- include "example-chart.labels" . | nindent 4 }}
spec:
type: {
{
.Values.service.type }}
ports:
- port: {
{
.Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{
{
- include "example-chart.selectorLabels" . | nindent 4 }}
The value of the referenced variable is in the file values.yaml In the definition of .
After deployment Helm According to the NOTES The text is stored in in NOTES.txt, And it is also templated .
chart Metadata , For example, the name of the deployed software 、 Version and version , In the file Chart.yaml It is specified in :
apiVersion: v2
name: mychart
description: A Helm chart for Kubernetes
...
type: application
...
version: 0.1.0
...
appVersion: "1.16.0"
To check Helm What will be deployed , You can pass in --dry-run and --debug Point to helm install chart Catalog :
helm install example-chart --dry-run --debug ./example-chart
The output will be very long , And include all the final resource definitions that will be applied to your cluster . After modifying the chart , You can use helm upgrade Push the new version to Kubernetes.
When you need to share what you have done chart when , You can package it for distribution by running the following :
helm package ./example-chart
The output will be :
Successfully packaged chart and saved it to: .../example-chart-0.1.0.tgz
You can install packaged charts as you add them to the repository :
helm install example-chart example-chart-0.1.0.tgz
In this step , You created and deployed a custom chart . You also packed it , And understand its structure .
Conclusion
You know how to use it now Helm Install and upgrade the deployment software to Kubernetes colony .
You have added chart The repository , And learned how to use ArtifactHub Find them .
You also created a new customization chart And learned about the version revision and how to rollback when necessary .
More about creating custom charts , Please visit Official Guide .
边栏推荐
- Regular expression learning
- Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm
- First experience of flask
- Wine wechat initialization 96% stuck
- Paper time review MB2: build a behavior model for autonomous databases
- Modify the existing annotator name in the word document
- 1、 MFC introduction
- Excel文件处理工具类(基于EasyExcel)
- 91. (leaflet chapter) leaflet situation plotting - offensive direction drawing
- Routing policy in republishing
猜你喜欢

ROS manipulator movelt learning notes 3 | kinect360 camera (V1) related configuration

1、 MFC introduction

Weekly summary (*66): next five years

Video chat source code - one-to-one live broadcast system source code

Notes of Teacher Li Hongyi's 2020 in-depth learning series 9

Paper notes: accurate causal influence on discrete data

Redis memory analysis tool RMA usage

Branch and loop statements in C language learning

云计算三类巨头:IaaS、PaaS、SaaS,分别是什么意思,应用场景是什么?

Go基础笔记_4_map
随机推荐
MATLAB basic grammar (II)
QT project - security monitoring system (function realization of each interface)
MySQL common basic commands
Transmission download list, download file migration machine guide
Optaplanner will abandon DRL (drools) scoring method!!!
Zheng Huijuan: Research on application scenarios and evaluation methods of data assets based on the unified market
First experience of flask
必会面试题:1.浅拷贝和深拷贝_深拷贝
How to speculate on the Internet? Is it safe to speculate on mobile phones
Do you need to open an account to buy a wealth management product with a 6% income?
HTB-Aragog
Use of serial queues
指针与数组
做一个文艺的测试/开发程序员,慢慢改变自己......
50 places are limited to open | with the news of oceanbase's annual press conference coming!
2022 最 NB 的 JVM 基础到调优笔记, 吃透阿里 P6 小 case
剖析kubernetes集群内部DNS解析原理
codeforces round #797 ABCDEFG
Can the income of CICC securities' new customer financial products reach 6%? How to open an account?
Restructuredtext grammar summary for beginners