Helm V3 基本使用
1、部署Helm客户端
Helm客户端下载地址: https://github.com/helm/helm/releases 解压移动到 /usr/bin/ 目录即可。
wget https://get.helm.sh/helm-v3.8.1-linux-amd64.tar.gz
tar zxvf helm-v3.8.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/bin/
2、Helm 常用命令
命令 | 描述 |
---|---|
create | 创建一个chart并指定名字 |
install | 安装一个chart |
uninstall | 卸载一个release |
upgrade | 更新一个release |
rollback | 回滚之前版本 |
version | 查看helm客户端版本 |
dependency | 管理chart依赖 |
get | 下载一个release。可用子命令:all、hooks、manifest、notes、values |
history | 获取release历史 |
list | 列出release |
package | 将chart目录打包到chart存档文件中 |
pull | 从远程仓库中下载chart并解压到本地 # helm pull stable/mysql --untar |
repo | 添加,列出,移出,更新和索引chart仓库。可用子命令:add、index、list、remove、update |
search | 根据关键字搜索chart。可用子命令:hub、repo |
show | 查看chart详细信息。可用子命令:all、chart、readme、values |
status | 显示已命名版本的状态 |
template | 本地呈现模板 |
3、配置国内chart仓库
- 微软仓库 (http://mirror.azure.cn/kubernetes/charts/) 推荐此仓库,基本上官网有的chart这都有。
- 阿里仓库 (https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts)
- 官方仓库 (https://hub.kubeapps.com/charts/incubator) 官方chart仓库,国内有点不好使。
添加存储库:
helm repo add stable(名字) http://mirror.azure.cn/kubernetes/charts
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update
查看配置的存储库:
helm repo list
helm search repo stable
删除存储库:
helm repo remove aliyun
4、Helm基本使用
helm create %name%
$ helm create hellolworld
Creating hellworld
$ tree helloworld
hellworld
|-- Chart.yaml
|-- charts
|-- templates
| |-- NOTES.txt
| |-- _helpers.tpl
| |-- deployment.yaml
| |-- hpa.yaml
| |-- ingress.yaml
| |-- service.yaml
| |-- serviceaccount.yaml
| |-- tests
| |-- test-connection.yaml
|-- values.yaml
Chart.yaml
这个文件中包含的是Chart的元数据
apiVersion: v2
name: demo
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
values.yaml
这个文件中包含Chart的所有可用的配置项,及其默认值。在安装Chart时传递的配置项会覆写这些默认值。
# Default values for demo.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
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: ""
podAnnotations: {}
podSecurityContext: {}
# fsGroup: 2000
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
service:
type: ClusterIP
port: 80
ingress:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
nodeSelector: {}
tolerations: []
affinity: {}
charts目录
包含子chart的目录,这里没用到
templates目录
这个目录包含的是Kubernetes资源声明的模板文件,在安装时,Helm会把模板文件和配置项的值结合起来,得到Kuberbetes资源定义,并应用到Kuberbetes上。
操作演示
示例代码只要保留Deployment、Service和Service Account即可。
- 修改deployment.yaml
containers -> containerPort: 80->8080
- 修改健康监测节点的探针为 /hello
livenessProbe -> httpGet -> path: /hellp
readinessProbe -> httpGet -> path: /hello
- 添加环境变量来传递给微服务
app: -> prefix: "Hello"
- 设置微服务容器镜像的名称和标签
镜像的名称在values.yaml中设置,而标签则默认是在Chart.yaml中指定的应用版本号。在实际使用中,一般通过image.tag配置项来传递标签。
replicaCount: 1
image:
repository: nginx # local/helloworld
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
- 完成Chart的创建之后,就可以使用Helm来安装
helm install myhelloworld .
- 安装完成之后,还可以使用Helm来更新
helm upgrade --set app.prefix="Greetings" myhellwold .
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?