helm入门
简介
Helm是一个由CNCF孵化和管理的项目,用于对需要在Kubernetes 上部署的复杂应用进行定义、安装和更新。Helm以Chart的方式对应用软件进行描述,可以方便地创建、版本化、共享和发布复杂的应用软件。
helm3架构

helm3安装
#github地址
#https://github.com/helm/helm
#本文示例使用的是v3.7.0版本
wget https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz
#解压->helm放入PATH一个路径下
helm中三大概念
- Chart:一个Helm包,其中包含运行一个应用所需要的工具和资源定义,还可能包含Kubernetes集群中的服务定义,类似于Homebrew 中的formula、APT中的dpkg或者Yum中的RPM文件。
- Release:在Kubernetes集群上运行的一个Chart实例。在同一个 集群上,一个Chart可以被安装多次。例如有一个MySQL Chart,如果想在服务器上运行两个MySQL数据库,就可以基于这个Chart安装两次。 每次安装都会生成新的Release,会有独立的Release名称。
- Repository:用于存放和共享Chart仓库。 简单来说,Helm整个系统的主要任务就是,在仓库中查找需要的 Chart,然后将Chart以Release的形式安装到Kubernetes集群中。
Helm Chart的使用
下面将使用一个例子展示helm chart的使用。
创建
$ helm create nginx
该命令会创建一个nginx文件目录,tree查看目录结构
$ tree
.
├── charts #包含chart依赖的其他chart
├── Chart.yaml #包含了chart信息的YAML文件
├── templates #模板目录, 当和values 结合时,可生成有效的Kubernetes manifest文件
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests #测试
│ └── test-connection.yaml
└── values.yaml #chart 默认的配置值
Chart.yaml
$ cat Chart.yaml
apiVersion: v2 #在heml3中apiVersion必须是v2
name: nginx #chart名字
description: A Helm chart for Kubernetes #chart描述
type: application #chart类型 application(默认)、library
version: 0.1.0 #chart的版本
appVersion: "1.16.0" #应用的版本
values.yaml
$ cat values.yaml
# Default values for nginx.
# 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: {
}
templates目录下存放了应用编排文件。
-
(_)开头的文件用来存储局部和辅助对象,供其他chart模板使用。模板命令都是嵌入在
{ {和}}之间的。cat _helpers.tpl { { /* Expand the name of the chart. */}} { { - define "nginx.name" -}} { { - default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} { { - end }} { { /* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). If release name contains chart name it will be used as a full name. */}} { { - define "nginx.fullname" -}} { { - if .Values.fullnameOverride }} { { - .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} { { - else }} { { - $name := default .Chart.Name .Values.nameOverride }} { { - if contains $name .Release.Name }} { { - .Release.Name | trunc 63

最低0.47元/天 解锁文章
2269

被折叠的 条评论
为什么被折叠?



