关于helm:helm实战入门

2次阅读

共计 3113 个字符,预计需要花费 8 分钟才能阅读完成。

一:介绍

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: v1
kind: ConfigMap
metadata:
  name: helloworld-configmap
data:
  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: v1
kind: ConfigMap
metadata:
  name: {{.Release.Name}}
data:
  value: "Hello World"

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

name: hw-from-values
apiVersion: v1
kind: ConfigMap
metadata:
  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-repo
helm 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: 1
    num2: 2

    add 示例

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{.Release.Name}}-configmap
    data:
      myvalue: "Hello World"
      sum: {{add .Values.num1 .Values.num2}}

    关系运算符

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

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{.Release.Name}}-configmap
    data:
      myvalue: "Hello World"
      on: {{not .Values.num1}}

    流控制

    if else

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{.Release.Name}}-configmap
    data:
      myvalue: "Hello World"
      {{- if eq "coffee1" "coffee"}}
      mug: "true"
      {{- end}}

    range

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{.Release.Name}}-configmap
    data:
      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 改版。

正文完
 0