- 1. Helm定义
- 2. Helm Chart的组成
- Chart.yaml
- Values.yaml
- templates文件夹
- 3. Helm Chart的安装
- 3.1. 纯安装
- - 安装本地chart
- - 安装远程数据库中的chart
- 3.2. 修改➕安装
- 其他有用的Helm命令
Helm是一个kubernetes上的软件包管理工具,标志是一个船舵 ☸️。
与NodeJS的软件包管理工具npm相似,Helm的目的也是方便打包,分享,管理App。Helm支持macOS,Linux和Windows系统。
类比
| Helm | NPM | |
|---|---|---|
| 基于。。。 | kubernetes | NodeJS |
| 软件包的叫法 | Chart | Package |
使用helm create myapp生成一个名为myapp的Helm Chart,该命令会自动生成一些列文件如下图:
包括两种数据:
- 元数据:chart的名字,版本,描述等
- 依赖
# metadata apiVersion: v2 name: myapp description: A Helm chart for Kubernetes type: application version: 0.1.0 appVersion: "1.16.0" # dependencies dependencies: - name: mariadb version: 7.0.1 repository: http://charts.bitnami.com
⚠️ 新添加了dependencies之后需要下载依赖到charts文件夹下。
helm dependency update
不然的话,你大概率会看到这个错误信息:
ERROR: found in Chart.yaml, but missing in charts/ directory: mariadb
执行下载依赖之后你能看到该依赖的包:
包含一些配制的默认值,以键值对的形式写出来。该文件中的值一般会被重写。
replicaCount: 1
image:
repository: nginx
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
templates文件夹
该文件夹中的所有文件都是YAML格式的模版(templates)。举例deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "myapp.fullname" . }}
labels:
{{- include "myapp.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "myapp.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "myapp.selectorLabels" . | nindent 8 }}
其中有一些比较特殊的文件:
- _helpers.tpl提供了一些写模版时建议用到的语法。比如添加标签labels
- NOTES.txt 相当于一个可模版化的README,可以写一些提示安装chart成功的信息,或者该Chart的使用方法等等
在myapp文件夹外部:
helm install myfirstrelease ./myapp- 安装远程数据库中的chart
数据库: https://artifacthub.io
helm install myfirstrelease my-repo/myapp3.2. 修改➕安装
我们之前说过Values.yaml中都是默认值,所以我们可以根据自己的需求对那些值进行重写,我们可以
(1)从某个文件从写:把要重写的值放在一个单独的YAML文件中
helm install myfirstrelease ./myapp -f custom.yaml
(2)直接在跑install命令时给键值对
helm install myfirstrelease ./myapp --set image.tag=master其他有用的Helm命令
| Helm命令 | 描述 |
|---|---|
| helm status myfirstrelease | 查看我安装的app myfirstrelease的状态 |
| helm list | 打印所有已安装的app列表,如果我现在执行应该能看到myfirstrelease |
| helm pull xChart | 从远程helm数据库下载某xChart |
| helm upgrade myfirstrelease ./myapp | 升级到新版本,比如在./myapp中修改了某个模版 |
| helm rollback myfirstrelease 1 | 将myfirstrelease滚回到版本1 |
| helm search | |
| helm show | |
| helm uninstall myfirstrelease | 取消appmyfirstrelease的安装 |
| helm delete myfirstrelease | 删除k8s集群上所有与myfirstrelease相关的资源 |
| helm template myfirstrelease myapp > base/deployment.yaml | 用Appmyfirstrelease中的内容生成一个YAML模版(chart位于文件夹myapp中),并储存到路径base/deployment.yaml中 可以拿来给kustomize用,会很方便,(kustomize会单独讲。。。在不远的未来) |
和其他文章一样,这篇文章也是我家猫咪Pepe舔出来的



