一:介绍

helm:helm官网文档

Helm is an open source package manager for Kubernetes. It provides the ability to provide, share, and use software built for Kubernetes.

上述是CNCF对于helm的一个简短的介绍,意思是说helm是kubernetes的一个包管理器,提供了为k8s提供、分享、构建软件的能力。类比于redhat系列的rpm、以及ubuntu的apt,都能够疾速散发并且装置软件。

基本概念

  1. chart:Helm软件包,它蕴含了在Kubernetes集群上运行利用、工具或服务所需的所有资源定义。chart对于k8s等同于MacOS brew、debain dpkg或redhat RPM的文件包。
  2. repo:chart仓库,收集、存储以及共享能够在k8s装置的charts。
  3. release:是Kubernetes集群中装置运行的一个chart实例。一个chart通常能够屡次装置到同一个集群中,每次装置时都会创立一个新版本。
  4. Config: Chart实例化装置运行时应用的配置信息。

二:实战

筹备利用

configmap-helloworld.yaml

apiVersion: v1kind: ConfigMapmetadata:  name: helloworld-configmapdata:  value: "Hello World"

生成 helloworld chart我的项目包

helm create helloworld

构造详情

helloworld/├── Chart.yaml            // chart根本信息文件├── charts├── templates        // 资源模版文件夹│   ├── NOTES.txt│   ├── _helpers.tpl│   ├── deployment.yaml│   ├── hpa.yaml│   ├── ingress.yaml│   ├── service.yaml│   ├── serviceaccount.yaml│   └── tests        // 测试相干文件夹│       └── test-connection.yaml└── values.yaml     // 参数变量文件

删除templates文件夹下文件,替换成如上configmap文件,查看最终要部署的内容

helloworld├── Chart.yaml├── charts├── templates│   └── configmap-helloworld.yaml└── values.yaml

--dry-run 模仿执行

 helm install --dry-run hw helloworld/

读值形式

从Release读取

apiVersion: v1kind: ConfigMapmetadata:  name: {{ .Release.Name }}data:  value: "Hello World"

从values文件读取 留神:《当初配置文件里退出参数name》

name: hw-from-valuesapiVersion: v1kind: ConfigMapmetadata:  name: {{ .Values.name }}data:  value: "Hello World"

从参数读取

helm install  hw --dry-run helloworld/ --set name=hw-from-parammm

公有charts仓库搭建

装置chartmuseum repo

helm repo add chartmuseum https://chartmuseum.github.io/charts

生成 helloworld chart我的项目包

helm install chartmuseum  chartmuseum/chartmuseum  --set persistence.enabled=true --set persistence.storageClass="rook-cephfs" --set persistence.pv.capacity.storage=20Gi --set env.open.DISABLE_API=false --set env.secret.BASIC_AUTH_USER=aaaa --set env.secret.BASIC_AUTH_PASS=bbbb

helm push插件装置

helm plugin install https://github.com/chartmuseum/helm-push

到此,公有repo 仓库筹备结束。

打包以及repo部署

集群增加公有repo仓库

helm repo add my-repo http://10.90.x.x:8080 

打包

helm package 

装置

helm install  hw --dry-run helloworld-0.1.0.tgz

将chart包推送到仓库

helm cm-push helloworld-0.1.0.tgz my-repo

通过仓库装置

helm repo update my-repohelm install hw my-repo/helloworld --set name=hw-newww

templates 语法

内置办法

Release 用法 {{ .Release.Name }} {{ .Release.Namespace }} …
Values 用法 {{ .Values.name }} {{ .Values.app.image }} …
Chart 用法 {{ .Chart.Name }} {{ .Chart.Version }} …

运算符

算数运算符

  • add sub min max mod …
    values.yaml 退出参数

    num1: 1num2: 2

    add示例

    apiVersion: v1kind: ConfigMapmetadata:  name: {{ .Release.Name }}-configmapdata:  myvalue: "Hello World"  sum: {{ add .Values.num1 .Values.num2 }}

    关系运算符

  • and or not eq ne lt gt …
    not示例:

    apiVersion: v1kind: ConfigMapmetadata:  name: {{ .Release.Name }}-configmapdata:  myvalue: "Hello World"  on: {{ not .Values.num1 }}

    流控制

    if else

    apiVersion: v1kind: ConfigMapmetadata:  name: {{ .Release.Name }}-configmapdata:  myvalue: "Hello World"  {{- if eq "coffee1" "coffee" }}  mug: "true"  {{- end }}

    range

    apiVersion: v1kind: ConfigMapmetadata:  name: {{ .Release.Name }}-configmapdata:  myvalue: "Hello World"  sizes: |- {{- range tuple "small" "medium" "large" }} - {{ . | quote }} {{- end }}   

常用命令

装置

helm install <RELEASENAME> <CHART>

卸载

helm uninstall <RELEASENAME> 

更新

helm upgrade <RELEASENAME> <CHART> --set key=value

搜寻chart

helm search rpeo

推送chart包到仓库

helm push

查看release版本

helm history

回滚

helm rollback

查看

helm show

创立chart包我的项目

helm create

参考:
helm仓库
官网下载

如有@侵权,请分割 2787950493@qq.com 改版。