helm v3

一、helm的引入

当应用太多,yaml文件多、杂,管理和维护成本加重。引入helm包管理器,chart打包一堆yaml文件,统一部署。

Chart.yaml · Helm (zhaowenyu.com)

二、名词概念

Helm | 从这里开始吧

1、文件结构

1
2
3
4
5
6
7
8
9
10
wordpress/
  Chart.yaml          # 包含了chart信息的YAML文件
  values.yaml         # chart 默认的配置值
  values.schema.json  # 可选: 一个使用JSON结构的values.yaml文件
  charts/             # 包含chart依赖的其他chart
  crds/               # 自定义资源的定义
  templates/          # 模板目录, 当和values 结合时,可生成有效的Kubernetes manifest文件
  templates/NOTES.txt # 可选: 包含简要使用说明的纯文本文件
  LICENSE             # 可选: 包含chart许可证的纯文本文件
  README.md           # 可选: 可读的README文件

三、helm  v3的安装

v3的安装比v2简单快捷,不需要做授权操作,将二进制可执行文件放入到/usr/bin/即可

Release Helm 3.9.4 · helm/helm · GitHub 最新下载地址

1
2
3
4
5
wget https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz
 
tar xzvf helm-v3.2.1-linux-amd64.tar.gz -C /usr/local/src
 
mv /usr/local/src/linux-amd64/helm /usr/local/bin/

1、官网  

https://helm.sh/docs/

Helm | 快速入门指南

2、解压安装

1
2
3
4
5
6
7
8
# tar zxvf helm-v3.0.0-linux-amd64.tar.gz
# cd linux-amd64/
# ls
helm  LICENSE  README.md
# mv helm  /usr/bin/
 
# helm   version
version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}

3、配置helm仓库

https://help.aliyun.com/document_detail/131467.html   helm使用阿里私有仓库

1
2
3
4
5
6
7
8
9
10
11
添加公有仓库如下
# helm repo add apphub https://apphub.aliyuncs.com   添加Helm Hub “中国站”
"apphub" has been added to your repositories
 
# helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts 
"stable" has been added to your repositories
 
# helm repo list
NAME      URL                                                  
apphub    https://apphub.aliyuncs.com   (apphub和stable是自定义repo名称)                        
stable    https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

移除和更新仓库

1
2
3
4
5
6
7
helm  repo  remove  仓库名
 
helm repo  update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "apphub" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈

search搜索应用(指定repo所有仓库)

1
2
3
4
5
6
# helm search repo harbor/harbor
 
NAME CHART VERSION APP VERSION DESCRIPTION
harbor/harbor 1.10.0 2.6.0 An open source trusted cloud native registry th...
 
# helm search repo ${keyword}   查看所有的资源

只下载不安装

1
2
3
4
$ helm pull harbor/harbor --version=1.10.0
 
$ ls
harbor-1.10.0.tgz

查询已经部署的服务

1
2
3
helm ls -n  namespce
 
NAME    NAMESPACE   REVISION    UPDATED STATUS  CHART   APP VERSION

查看历史版本

1
2
3
helm history -n  moqi   app_name
 
REVISION    UPDATED                     STATUS      CHART                   APP VERSION DESCRIPTION

回滚历史版本

1
helm rollback -n  namespace  app_name

helm completion bash

为Helm生成针对于bash shell的自动补全脚本。

在当前shell会话中加载自动补全:

1
source <(helm completion bash)

linux

1
helm completion bash > /etc/bash_completion.d/helm

helm安装搜索的某个应用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# helm install  ui  apphub/weave-scope  (ui自己取的名称)
NAME: ui
LAST DEPLOYED: Tue Sep 22 22:36:12 2020
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/

 

修改ClusterIP为NodePort,部署成功。

 

 查看安装后的状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# helm list
NAME    NAMESPACE   REVISION    UPDATED                                 STATUS      CHART               APP VERSION
ui      default     1           2020-09-22 23:03:12.207890113 +0800 CST deployed    weave-scope-1.1.8   1.12.0    
 
# helm status  ui
NAME: ui
LAST DEPLOYED: Tue Sep 22 23:03:12 2020
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/

六、自定义chart

k8s-tutorials/helm.md at main · guangzhengli/k8s-tutorials (github.com)

1、生成一个chart模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
➜  helm create k8s-helm
Creating k8s-helm
 
➜  tree k8s-helm
k8s-helm
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│   └── test-connection.yaml
└── values.yaml
 
3 directories, 10 files
 
注:templates里面存放自己的yaml文件   values.yaml存放全局变量,用于yaml的高复用  Chart.yaml用来定义一些chart的属性

名称以下划线(_)开头的文件被假定为没有内部 manifest。这些文件不会渲染 Kubernetes 对象定义,而是在其他 chart 模板中随处可用以供调用。

https://whmzsu.github.io/helm-doc-zh-cn/chart_template_guide/named_templates-zh_cn.html

2、在templates 里面存放自己的yaml文件

3、安装自定义chart

1
heml  install  web  mychart/

4、升级

1
2
3
heml  upgrade   mychart/
 
helm upgrade cloude-native-gitlab --values values.yaml gitlab-offical/gitlab

5、查看release列表

1
helm list --namespace ${namespace}

七、chart资源的高复用

传递参数,动态渲染模板,yaml的内容通过传参生成

修改values.yaml文件,{{  .Release.Name}} {{  .Values.变量名}}

还有待学习领悟

八、chart包管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 本地创建一个 Chart
helm create <Chart 名称>
 
// 安装helm-push插件,可能会卡
[root@master01 msxu]# helm plugin install https://github.com/chartmuseum/helm-push.git
 
# 推送 Chart 目录
helm push <Chart 名称> <本地仓库名称>
 
# 或者推送 Chart 压缩包
helm push <Chart 名称>-<Chart 版本>.tgz <本地仓库名称>  
 
# 从线上 Chart 仓库更新本地 Chart 索引
helm repo update
 
# 拉取 Chart
helm fetch <本地仓库名称>/<Chart 名称> --version <Chart 版本>
 
# 或者直接安装 Chart
helm install -f values.yaml <本地仓库名称>/<Chart 名称> --version <Chart 版本>

九、离线安装helm插件

1、查看helm的plugin路径

2、在该路径下创建helm-push文件夹,并将安装包拷贝到该文件夹下解压即可

1
2
3
4
5
6
7
8
mkdir /root/.local/share/helm/plugins/helm-push
 
cp helm-push_0.9.0_linux_amd64.tar.gz /root/.local/share/helm/plugins/helm-push
 
cd /root/.local/share/helm/plugins/helm-push
tar zxvf helm-push_0.9.0_linux_amd64.tar.gz
 
helm plugin list

  

 

 

Helm | 从这里开始吧 中文官网

https://www.jianshu.com/p/11828ace23f9

https://www.cnblogs.com/pythonPath/p/12667509.html  新工具kustomize

https://segmentfault.com/a/1190000022583522?utm_source=tag-newest

https://github.com/bitnami/charts/tree/master/bitnami  一个不错的heml仓库





 

 

posted @   凡人半睁眼  阅读(387)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示