当前位置: 首页 > news >正文

容器编排大王Kubernetes——helm包管理工具(8)

概念:

helm简介

image-20251024211111095

  • Helm是Kubernetes 应用的包管理工具,主要用来管理 Charts,类似Linux系统的yum/dnf,charts就是rpm。
  • Helm Chart是用来封装Kubernetes原生应用程序的一系列YAML文件。可以在你部署应用的时候自定义应用程序的一些 Metadata,以便于应用程序的分发。
  • 对于应用发布者而言
  • 通过Helm打包应用、管理应用依赖关系、管理应用版本并发布应用到软件仓库。
  • 对于使用者而言
  • 使用Helm后可以以简单的方式在Kubernetes上查找、安装、升级、回滚、卸载应用程序

官网与资源

官网: https://helm.sh/zh/docs/intro/quickstart/

软件资源: https://github.com/helm/helm/releases

实验操作:

一 部署helm

1.安装helm

[root@master mnt]# tar zxf helm-v3.19.0-linux-amd64.tar.gz
[root@master mnt]# ls
helm-v3.19.0-linux-amd64.tar.gz 
[root@master helm]# cd  linux-amd64/
[root@master linux-amd64]# ls
helm  LICENSE  README.md
[root@master linux-amd64]# cp -p helm  /usr/local/bin/

2.配置helm命令补齐

[root@master linux-amd64]# echo "source <(helm completion bash)" >> ~/.bashrc
root@master linux-amd64]# source   ~/.bashrc
[root@master linux-amd64]# helm version
version.BuildInfo{Version:"v3.19.0", GitCommit:"3d8990f0836691f0229297773f3524598f46bda6", GitTreeState:"clean", GoVersion:"go1.24.7"}

二 helm常用操作

2.1 常用命令

命令描述
create创建一个 chart 并指定名字
dependency管理 chart 依赖
get下载一个 release。可用子命令:all、hooks、manifest、notes、values
history获取 release 历史
install安装一个 chart
list列出 release
package将 chart 目录打包到 chart 存档文件中
pull从远程仓库中下载 chart 并解压到本地 # helm pull stable/mysql – untar
repo添加,列出,移除,更新和索引 chart 仓库。可用子命令:add、index、 list、remove、update
rollback从之前版本回滚
search根据关键字搜索 chart。可用子命令:hub、repo
show查看 chart 详细信息。可用子命令:all、chart、readme、values
status显示已命名版本的状态
template本地呈现模板
uninstall卸载一个 release
upgrade更新一个 release
version查看 helm 客户端版本

2.2 helm仓库的管理

以下为常用的仓库源

  • 阿里云仓库:https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
  • bitnami仓库: https://charts.bitnami.com/bitnami
  • 微软仓库:http://mirror.azure.cn/kubernetes/charts/
  • 官方仓库: https://hub.kubeapps.com/charts/incubator
[root@k8s-master helm]# helm search  hub nginx		#在官方仓库中搜索
[root@k8s-master helm]# helm  search  repo  nginx	#在本地仓库中搜索

添加第三方repo源

#添加阿里云仓库
[root@master helm]# helm repo  add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"aliyun" has been added to your repositories#添加bitnami仓库
[root@master helm]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories#添加微软仓库
[root@master helm]# helm repo add azure http://mirror.azure.cn/kubernetes/charts/
"azure" has been added to your repositories#查看仓库信息
[root@master helm]# helm repo list
NAME    URL
aliyun  https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
azure   http://mirror.azure.cn/kubernetes/charts/
bitnami https://charts.bitnami.com/bitnami#查询某个源的包并过滤nginx的包
[root@master helm]# helm search repo aliyun | grep nginx#删除第三方源
[root@master helm]# helm repo remove azure
[root@master helm]# helm repo list
NAME    URL
aliyun  https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
bitnami https://charts.bitnami.com/bitnami#查看仓库存储helm清单
[root@k8s-master helm]# helm search repo  aliyun
NAME                            CHART VERSION   APP VERSION     DESCRIPTION         #应用名称						  封装版本			软件版本          软件描述                   
aliyun/acs-engine-autoscaler    2.1.3           2.1.1           Scales worker nodes within agent pools           
aliyun/aerospike                0.1.7           v3.14.1.2       A Helm chart for Aerospike in Kubernetes 
......

2.3 helm的使用方法

1.查找chart包

#repo为从添加的第三方源中查找,hub为从官方源查找
[root@master helm]# helm search repo nginx
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION
aliyun/nginx-ingress                    0.9.5           0.10.2          An nginx Ingress controller that uses ConfigMap...
aliyun/nginx-lego                       0.3.1                           Chart for nginx-ingress-controller and kube-lego
bitnami/nginx                           22.2.1          1.29.2          NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller        12.0.7          1.13.1          NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel                     2.1.15          0.4.9           DEPRECATED NGINX Open Source for Intel is a lig...
aliyun/gcloud-endpoints                 0.1.0                           Develop, deploy, protect and moni

2.查看chart包信息

#查找出来后进行信息的查看
[root@master helm]# helm show chart aliyun/nginx-ingress
apiVersion: v1
appVersion: 0.10.2
description: An nginx Ingress controller that uses ConfigMap to store the nginx configuration.
icon: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Nginx_logo.svg/500px-Nginx_logo.svg.png
keywords:
- ingress
- nginx
maintainers:
- email: jack.zampolin@gmail.comname: jackzampolin
- email: mgoodness@gmail.comname: mgoodness
- email: chance.zibolski@coreos.comname: chancez
name: nginx-ingress
sources:
- https://github.com/kubernetes/ingress-nginx
version: 0.9.5

3 安装chart包

[root@master ~]# helm install fjwyyy bitnami/nginx
[root@master ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART            APP VERSION
fjwyyy       default         1               2024-09-10 12:08:12.3165525 +0800 CST   deployed        nginx-18.1.11    1.27.1[root@k8s-master ~]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
fjwyyy-nginx-8598578bcf-qjwwq   1/1     Running   0          41s#查看项目的发布状态
[root@master ~]# helm status fjwyyy
NAME: fjwyyy
LAST DEPLOYED: Tue Sep 10 12:08:12 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 18.1.11
APP VERSION: 1.27.1#卸载项目
[root@master nginx]# helm uninstall fjwyyy
release "fjwyyy" uninstalled[root@master nginx]# kubectl get pods
No resources found in default namespace.[root@master nginx]# helm list
NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION

2.5 安装项目前预定义项目选项


[root@master helm]# docker load -i nginx-1.27.1-debian-12-r2.tar
[root@master nginx]# docker tag bitnami/nginx:1.27.1-debian-12-r2 reg.fy.org/bitnami/nginx:1.27.1-debian-12-r2
[root@master nginx]# docker push reg.fy.org/bitnami/nginx:1.27.1-debian-12-r2[root@master nginx]# helm install fjw /root/helm/nginx

image-20250822105630237

三 构建helm中的chart包

3.1 Helm Chart目录结构

#建立chart项目
[root@master helm]# helm create fjwyyy
Creating fjwyyy[root@master helm]# tree fjwyyy/
fjwyyy/
├── charts								#目录里存放这个chart依赖的所有子chart。
├── Chart.yaml							#用于描述这个 Chart 的基本信息,包括名字、描述信息以及版本等。	
├── templates							#目录里面存放所有 yaml 模板文件。				
│   ├── deployment.yaml
│   ├── _helpers.tpl					#放置模板助手的地方,可以在整个 chart 中重复使用
│   ├── hpa.yaml
│   ├── httproute.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml							#用于存储 templates 目录中模板文件中用到变量的值。

3.2 构建方法

编写chart文件

[root@master fjwyyy]# vim Chart.yaml
apiVersion: v2
name: fjwyyy
description: A Helm chart for Kubernetes
type: application
version: 0.1.0				#项目版本
appVersion: "v1"			#软件版本[root@master fjwyyy]# vim values.yaml
replicaCount: 2						#运行pod的数量
image:repository: myapp					#运行的镜像pullPolicy: IfNotPresenttag: "v1"
ingress:enabled: true						#使用ingress暴露端口className: "nginx"annotations: {}# kubernetes.io/ingress.class: nginx# kubernetes.io/tls-acme: "true"hosts:- host: www.fjwyyy.orgpaths:- path: /pathType: ImplementationSpecific#语法检测
[root@master fjwyyy]# helm lint .
==> Linting .
[INFO] Chart.yaml: icon is recommended1 chart(s) linted, 0 chart(s) failed#运行项目
[root@master helm]# helm install myapp fjwyyy
NAME: myapp
LAST DEPLOYED: Fri Oct 24 23:31:15 2025
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:http://www.fjwyyy.org/[root@master helm]# kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
myapp-fjwyyy-9fd96499-tvhb9   1/1     Running   0          31s
myapp-fjwyyy-9fd96499-xgx4c   1/1     Running   0          31s#删除项目
[root@master helm]# helm uninstall myapp
release "myapp" uninstalled

项目打包并运行

#项目打包
[root@master helm]# helm package fjwyyy/
Successfully packaged chart and saved it to: /root/helm/fjwyyy-0.1.0.tgz
[root@master helm]# ls
fjwyyy  fjwyyy-0.1.0.tgz#项目可以通过各种分享方式发方为任何人后部署即可
[root@master helm]# helm install testhelm fjwyyy-0.1.0.tgz
NAME: testhelm
LAST DEPLOYED: Fri Oct 24 23:36:47 2025
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:http://www.fjwyyy.org/
[root@master helm]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
testhelm-fjwyyy-86dfcf84f4-6vkm2   1/1     Running   0          5s
testhelm-fjwyyy-86dfcf84f4-pw2xr   1/1     Running   0          5s
[root@master helm]# kubectl get ingress
NAME              CLASS   HOSTS            ADDRESS   PORTS   AGE
testhelm-fjwyyy   nginx   www.fjwyyy.org             80      8s

四 helm的版本迭代

1.更新应用

[root@master helm]# helm upgrade fjw fjwyyy/fjw[root@master helm]# curl www.fy.org
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>

2.显示项目版本

#可以看到更新跟回滚过的版本
[root@master helm]# helm history fjw

image-20250822120006661

3.应用回滚

#查看项目版本后,回滚想要回去的版本号
[root@master helm]# helm rollback fjw 8[root@master helm]# curl www.fy.org
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
http://www.dtcms.com/a/524047.html

相关文章:

  • 南皮县网站建设php网站开发接口开发
  • 【AOA定位与UKF例程】到达角度(AOA)定位后,使用无迹卡尔曼滤波(UKF)对轨迹滤波,MATLAB例程可下载
  • 拒绝笨重,一款轻量、极致简洁的开源CI/CD工具 - Arbess
  • JavaWeb--Servlet
  • 【机器学习】15.深度聚类(Deep Clustering)原理讲解与实战
  • Atom编辑器下载安装图文教程(附安装包)
  • 【基础复习1】ROC 与 AUC:逻辑回归二分类例子
  • 【Angular 】Angular 中的依赖注入
  • 做门户网站需要什么条件文化传播公司网站模版
  • 马斯克公司推出视频模型 Imagine v0.9,实测解析
  • 扶风做企业网站网站建设平台安全问题有哪些方面
  • 【AI4S】Motif-Driven Contrastive Learning of Graph Representations
  • Flutter路由使用指南
  • husky vs lefthook:新一代 Git Hooks 工具全面对比
  • Go Web 编程快速入门 07 - 模板(1):语法与最佳实践
  • 聊城网站建设信息兴义网站建设网站建设
  • 今年前三季度浙江进出口总值首破四万亿元
  • 【一文了解】八大排序-插入排序、希尔排序
  • n8n数据存储在postgres
  • 数据结构——冒泡排序
  • 医疗连续体机器人模块化控制界面设计(2025年更新版Python库)
  • 做网站服务器需要系统wordpress折腾怕了
  • 022数据结构之树状数组——算法备赛
  • 从 TypeScript 到 Java(4):访问修饰符与作用域 —— Java 的封装哲学
  • 做网站要有什么团队上海网站营销推广
  • 残差网络的介绍及ResNet-18的搭建(pytorch版)
  • WPF绘制界面常用功能
  • vbs笔记 【未完更】
  • 不用服务器也能搭博客!Docsify+cpolar的极简方案
  • 一文了解开源大语言模型文件结构,以 Hugging Face DeepSeek-V3.1 模型仓库为例