chart的简单使用
文章目录
1. 创建chart
在当前目录下创建了一个叫my-hello-world的 chart。
# helm create my-hello-world
2 chart的结构
可见chart中包含如下目录和文件
# ll 总用量 16 drwxr-x--- 4 root 93 9月 22 17:54 . drwxrwxrwt. 11 root 4096 9月 22 18:03 .. drwxr-x--- 2 root 6 9月 22 17:54 charts -rw-r----- 1 root 912 9月 22 17:54 Chart.yaml -rw-r----- 1 root 342 9月 22 17:54 .helmignore drwxr-x--- 3 root 146 9月 22 17:54 templates -rw-r----- 1 root 1497 9月 22 17:54 values.yaml
说明:
charts
目录: [可选],该目录中放置当前Chart依赖的其它Chart
Chart.yaml
:用于描述Chart的基本信息,包括名称版本等
templates
目录: 部署文件模版目录
values.yaml
文件: 为templates目录中的yaml文件提供变量
2.2 charts目录
说明:放置当前Chart依赖的其它Chart,如:
安装 prometheus-operator ,需要在chart目录下创建chart目录放置它依赖的expoter、grafana的chart文件
2.3 Chart.yaml
# cat Chart.yaml apiVersion: v1 appVersion: "1.0" # 内部版本 description: A Helm chart for Kubernetes name: my-hello-world version: 0.1.0 # chart版本
2.4 templates和yaml文件
存放k8s中创建对象的yaml文件
刚才的hello-world只创建了deployment和service。如果我们愿意,可以放入任何对象的yaml文件,如pv,pvc,configmap,secret等
2.5 values.yaml和变量的使用
说明:
values.yaml中的变量会被 templates中的yaml文件中自动使用。
下边是一个简单的使用示例,我们会在进阶文档中展示更多用法
- 如 values.yaml中变量定义如下:
################################### # 使用的镜像 # ################################### images: ApigwIot: registry.cn-zhangjiakou.aliyuncs.com/iot-xxx/svc.apigw ApigwTag: 1.1.1 ConsulIot: registry.cn-zhangjiakou.aliyuncs.com/iot-xxx/consul ConsulTag: latest
- 在yml中使用如下:
spec: containers: - name: iot-apigw image: {{ .Values.images.ApigwIot }}:{{ .Values.images.ApigwTag }} imagePullPolicy: Always
3 检查chart和查看
3.1语法检查
# helm lint --strict /root/yml/my-hello-world/ ==> Linting /root/yml/my-hello-world/ [INFO] Chart.yaml: icon is recommended 1 chart(s) linted, no failures
3.2 查看最终yaml文件
执行下边命令可显示最终yml文件。
# helm install --dry-run --debug /root/yml/my-hello-world
输出结果中变量已经被替换的最终yml文件。
如果有判断也会显示最后选择的结果。
4 chart打包和上传
- 打包
# helm package ./my-hello-world/ Successfully packaged chart and saved it to: /tmp/my-hello-world-0.1.0.tgz
说明:会在当前目录生成一个压缩包
- 上传
以后会在harbor仓库的chart库中说明
5. chart的使用
- 利用chart包安装
# helm install my-hello-world -n test /root/yml/my-hello-world/my-hello-world-0.1.0.tgz
说明:
my-hello-world
为创建的Release名
test
为安装到的namespace。
-
利用chart目录安装
语法:
helm install release_name -n namespace_name chart_dir
-
利用helm仓库安装
语法:
helm install release_name -n namespace_name repot_name/chart_name
6 .官方的chart
- 旧地址:
https://github.com/helm/charts - 新地址
https://artifacthub.io/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?