helm chart 快速入门
个人blog传送门
概述
helm chart 是一种描述如何部署应用到 kubernetes 中的文档格式。
helm 项目提供了命令行工具 helm 来进行部署包的管理,并且支持接入 chart 仓库,如果你用过 linux 各大发行版的源,或者 docker 的镜像仓库,相信可以迅速 Get 到这种方案理念。目前官方的中央仓库为 artifacthub。
下载一个 helm 3 执行程序到本地,然后我们可以通过执行helm repo add <repo-name> <repo-url>
来添加开发环境的 chart 仓库。helm search repo <repo-name>
可以浏览当前仓库中有的 chart。
使用helm create <charts-name>
可以创建一个初始 chart,文件结构如下:
# tree mychart
mychart
├── charts/ # 子 chart
├── Chart.yaml # chart 的概要信息
├── templates # 模板,对标 k8s 中的种种资源类型
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml # 一些需要传递给模板的值被放置在这里
除了 Chart.yaml、values.yaml 是必须要有的,其他都是可选的。当然在实际使用时,我们无疑是需要 templates/ 里的模板的,比如 deployment.yaml、service.yaml,模板从 values.yaml 中获取值来渲染得到最终的部署相关资源描述文件。
Chart.yaml
Chart.yaml 中主要是放一些概要信息,比如 chart 的名称、版本、维护者、依赖(即子 chart)。
name: mychart
description: A Helm chart for Kubernetes
type: application # application or library
version: 0.1.0 # chart release version
appVersion: "1.16.0" # version of some application inside the chart, such as nginx. Just a message, not important# optional
maintainers:
- email: <>name: <># optional
dependencies:
- name: <>version: <>repository: <> # optional
注意在 Helm 3 中,不再需要 requirements.yaml 来描述 dependencies 。
在声明了 dependencies 的 chart 中执行helm dependency update
或helm dependency build
将会自动生成一个 Chart.lock 文件,且如果设置了依赖项的 repository,会到仓库中查找并打包为 .tgz 文件下载到 charts/ 路径下。
当然,你也可以直接使用helm pull <chart-name>
直接从仓库中抓取对应的 chart 到 charts/ 下。
values.yaml
values.yaml 中放置一些需要传递给模板的值,在模板文件中你将可以通过 {{.Values.xxx.xxx}} 来进行引用。
# Default values for mychart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1image:repository: nginxpullPolicy: IfNotPresent# Overrides the image tag whose default is the chart appVersion.tag: ""imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""serviceAccount:# Specifies whether a service account should be createdcreate: true# Annotations to add to the service accountannotations: {}# The name of the service account to use.# If not set and create is true, a name is generated using the fullname templatename: ""
podAnnotations: {}
podSecurityContext: {}# fsGroup: 2000
securityContext: {}# capabilities:# drop:# - ALL# readOnlyRootFilesystem: true# runAsNonRoot: true# runAsUser: 1000service:type: ClusterIPport: 80ingress:enabled: falseclassName: ""annotations: {}# kubernetes.io/ingress.class: nginx# kubernetes.io/tls-acme: "true"hosts:- host: chart-example.localpaths:- path: /pathType: ImplementationSpecifictls: []# - secretName: chart-example-tls# hosts:# - chart-example.localresources: {}# 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: 128Miautoscaling:enabled: falseminReplicas: 1maxReplicas: 100targetCPUUtilizationPercentage: 80# targetMemoryUtilizationPercentage: 80nodeSelector: {}tolerations: []affinity: {} route:host: xxx..cn
如果想要约束 values.yaml 中的配置结构,可以创建一个 values.schema.json,如下截取了对 values.yaml 中 route 设置结构的约束。
{"$schema": "http://json-schema.org/schema","properties": {..."route": {"properties": {"host": {"type": "string","description": "ingress full hostname for icc"}}}}
}
覆盖子 chart 配置
一个可用服务通常涉及到多个应用,比如业务应用会依赖 redis 之类中间件,这就是 Chart.yaml 中设置 dependencies 的用意。当我们依赖于别人提供的 chart,但在部署时又需要对其中的一些配置进行调整,这时候就可以通过在父 Chart.yaml 中设置能对应到子 chart 中 values.yaml 中的配置的配置项,来达到覆盖子 chart 中配置值的目的。
假设现在 mychart 有一个 mysubchart 的依赖。
# tree
.
├── charts
│ └── mysubchart
│ ├── charts
│ ├── Chart.yaml
│ ├── templates
│ └── values.yaml
├── Chart.yaml
├── templates
└── values.yaml
在 mychart/charts/mysubchart/values.yaml 中存在一个配置项 dessert。
dessert: cake
可以通过在 mychart/values.yaml 中设置另一个值来覆盖。指明子 chart 名称,然后是 values.yaml 中的路径即可。
mysubchart:dessert: ice-cream
最终,我们得到的 chart 的结构可能如下
# tree
.
├── Chart.lock
├── charts
│ ├── mysubchart
│ │ ├── charts
│ │ ├── Chart.yaml
│ │ ├── templates
│ │ │ ├── deployment.yaml
│ │ │ ├── _helpers.tpl
│ │ │ ├── hpa.yaml
│ │ │ ├── ingress.yaml
│ │ │ ├── NOTES.txt
│ │ │ ├── serviceaccount.yaml
│ │ │ ├── service.yaml
│ │ │ └── tests
│ │ │ └── test-connection.yaml
│ │ └── values.yaml
│ └── redis.tgz
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
├── values.schema.json
└── values.yaml
reference
https://helm.sh/zh/docs/chart_template_guide/getting_started/
helm chart 快速入门相关推荐
- Helm基本介绍及快速入门
文章目录 Helm基本介绍及快速入门 一.Helm基本介绍 Helm简介 Helm 相关组件及概念 二.Helm部署 Helm客户端安装 校验是否安装成功 三.Helm 使用 使用仓库(helm re ...
- 从入门到实践:创作一个自己的 Helm Chart
前言 我们平时在日常生活中会经常在不同的平台上与各种各样的应用打交道,比如从苹果的 App Store 里下载的淘宝.高德.支付宝等应用,或者是在 PC 端安装的 Word.Photoshop.Ste ...
- 深入浅出Istio:Service mesh快速入门与实践-读书笔记(By GisonWin)
01 服务网格历史 (以后补充) 02 服务网格的基本特性 连接 微服务错综复杂,要完成其业务目标,连接问题是首要问题.连接存在于所有服务的整个lifcecycle中,用于维持服务的运行. 安全 保障 ...
- Spread for Windows Forms快速入门(1)---开始使用Spread
2019独角兽企业重金招聘Python工程师标准>>> 前言 Spread for Windows Forms是功能最为强大的表格控件,拥有灵活开放的对象模型和50,000个以上的A ...
- 京东必考JVM 问题诊断快速入门
JVM 问题诊断快速入门 JVM 全称为 Java Virtual Machine,翻译为中文 "Java 虚拟机".本文中的JVM主要指 Oracle 公司的 HotSpot V ...
- java学习day51(AdminLTE)AdminLTE快速入门与应用
目录 简述 第一章-快速入门 第一节-概述与基本使用 第二节-快速入门案例 第二章-SSM界面 第一节-首页 第二节-登录页面 第三节-用户管理页面 第四节-角色管理页面 第五节-资源权限管理页面 第 ...
- Cobra 快速入门 - 专为命令行程序而生
最近一直在看 Istio(一个 Service Mesh 框架)相关的东西,当看到其源码时发现了一个新东西 Cobra,一查却发现这是个好东西,用的地方可不少,比如:Docker.Kubernetes ...
- Shiro第一个程序:官方快速入门程序Qucickstart详解教程
目录 一.下载解压 二.第一个Shiro程序 1. 导入依赖 2. 配置shiro配置文件 3. Quickstart.java 4. 启动测试 三.shiro.ini分析 四.Quickstart. ...
- 计算机入门新人必学,异世修真人怎么玩?新手快速入门必备技巧
异世修真人怎么快速入门?最近新出来的一款文字修仙游戏,很多萌新不知道怎么玩?进小编给大家带来了游戏新手快速入门技巧攻略,希望可以帮到大家. 新手快速入门攻略 1.开局出来往下找婆婆,交互给点钱,旁边有 ...
- Spring Boot 2 快速教程:WebFlux 快速入门(二)
2019独角兽企业重金招聘Python工程师标准>>> 摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘 ...
最新文章
- R语言dplyr包移除dataframe数据行实战(Remove Rows):按照条件移除数据行、按照索引移除数据行、删除包含NA值的所有数据行、删除具体列包含NA值的数据行
- 在微信小程序里自动获得当前手机所在的经纬度并转换成地址
- 从WildFly 9(子系统)中运行OkHttpClient
- 在python中用递归的方法编程_python基础之函数,递归,内置函数
- eclipse 开发环境配置
- java用linkedlist编写学生类_【S2第二学期-使用Java实现面向对象编程】Java平台的集合类(List、ArrayList、LinkedListMap、HashMap...
- 抗滑桩弹性计算方法_抗滑桩设计与计算99147
- 前端js如何生成一个对象,并转化为json字符串
- JDK安装包和Mysql安装包整理
- 免费ebook 好东东!一起分享
- ps制作动态html,PS制作动态海报教程
- Markdown中在线编辑公式LaTex
- 计算机中带符号的整数表示方法,带符号数的代码表示-数字电子技术-电子发烧友网站...
- Excel数据的筛选
- [BZOJ3993]-[SDOI2015]星际战争-二分答案+最大流
- 输入数独题目,程序输出数独的唯一解。保证所有已知数据的格式都是合法的,并且题目有唯一的解。
- matlab第一次学习成果
- 实验2:MIPS指令系统和MIPS体系结构
- 二维数组作为参数传递问题
- Android辅助功能(无障碍)使用---AccessibilityService