zoukankan      html  css  js  c++  java
  • helm v3使用指南|常见命令行(2) Marathon

    参考转载:

    前言

    Helm 是云原生领域最火热的应用管理工具。众所周知 Kubernetes 是自动化的容器管理平台,然而 Kubernetes 并没有抽象出应用的概念,通常应用的描述是非常复杂的,一个应用可能是由多种资源组成。例如一个典型的前后端分离的应用包含以下资源:

    web-application-deployment.yaml,前端 Web 服务。
    web-service.yaml,前端服务访问入口。
    backend-server-deployment.yaml,后端服务。
    backend-server-configmap.yaml,后端服务配置。
    backend-mysql.yaml,后端服务依赖的 Mysql 实例。
    backend-mysql-service.yaml,Mysql 实例访问入口。
    我们通过多次 kubectl apply -f 上述资源,但是后续无法有效管理应用所包含的资源。这也正是 Helm 要解决的难题,更好地帮助用户定义、部署以及管理应用。

    Helm核心概念

    Chart
    Helm 采用 Chart 的格式来标准化描述一个应用(K8S 资源文件集合),Chart 有自身标准的目录结构,可以将目录打包成版本化的压缩包进行部署。就像我们下载一个软件包之后,就可以在电脑上直接安装一样,同理 Chart 包可以通过 Helm 部署到任意的 K8S 集群中。

    Config
    Config 指应用配置参数,在 Chart 中由 values.yaml 和命令行参数组成。Chart 采用 Go Template 的特性 + values.yaml 对部署的模板文件进行参数渲染,也可以通过 Helm Client 的命令
    --set key=value 的方式进行参数赋值。

    Repository
    类似于 Docker Hub,Helm 官方、阿里云等社区都提供了 Helm Repository,我们可以通过 helm repo add 导入仓库地址,便可以检索仓库并选择别人已经制作好的 Chart 包,开箱即用。

    Hub
    不同的个人和组织提供的公共仓库形成了分散和分布的Helm仓库,不利于查找,所以官方提供了Helm Hub,各公共仓库可以注册到Helm Hub中以方便集中查找,Helm Hub只是分布的仓库的集中展示中心。

    仓库注册到Helm Hub时,会将Chart清单文件向Helm Hub同步一份,这样可以在Helm Hub集中展示仓库列表和各仓库中的Chart列表。

    Helm Hub地址为https://hub.helm.sh/charts,下图的左边为注册到Helm Hub中的仓库列表,点击仓库链接,右边为该仓库的Chart列表。

    Release
    Release 代表 Chart 在集群中的运行实例,同一个集群的同一个 Namespace 下 Release 名称是唯一的。Helm 围绕 Release 对应用提供了强大的生命周期管理能力,包括 Release 的查询、安装、更新、删除、回滚等。

    Helm V2 & V3 架构设计
    Helm V2 到 V3 经历了较大的变革,其中最大的改动就是移除了 Tiller 组件,所有功能都通过 Helm CLI 与 ApiServer 直接交互。Tiller 在 V2 的架构中扮演着重要的角色,但是它与 K8S 的设计理念是冲突的。

    • 围绕 Tiller 管理应用的生命周期不利于扩展。
    • 增加用户的使用壁垒,服务端需要部署 Tiller 组件才可以使用,侵入性强。
    • K8S 的 RBAC 变得毫无用处,Tiller 拥有过大的 RBAC 权限存在安全风险。
    • 造成多租户场景下架构设计与实现复杂。

    Helm v3常用命令

    索引

    • helm version
    • helm help
    • helm completion
    • helm env
    • helm repo
    • helm search
    • helm pull
    • helm install
    • helm list
    • helm uninstall
    • helm test
    • helm upgrade
    • helm status
    • helm history
    • helm rollback
    • helm get
    • helm create
    • helm show
    • helm template
    • helm dependency
    • helm lint
    • helm package
    • helm plugin
    • helm verify

    helm version

    # 查看版本
    helm versoin
    # 查看短版本
    helm version --short
    

    helm help

    查看命令行帮助,有以下几种方式:
    
    helm
    helm help
    helm help [command]
    helm -h(常用)
    helm --help
    helm [command] -h(常用)
    helm [command] -help
    helm [command] [sub command] -h(常用)
    helm [command] [sub command] -help
    查看命令行帮助。
    

    helm completion

    yum install -y bash-completion
    source /usr/share/bash-completion/bash_completion
    source <(helm completion bash)
    
    # 顺便补全kubectl。
    source <(kubectl completion bash)
    
    helm <tab>
    completion  dependency  get         install     list        plugin      repo        search      status      test        upgrade     version
    create      env         history     lint        package     pull        rollback    show        template    uninstall   verify
    

    helm env

    # 打印出Helm使用的所有环境变量。
    helm env
    HELM_KUBECONTEXT=""
    HELM_BIN="helm"
    HELM_DEBUG="false"
    HELM_PLUGINS="/root/.local/share/helm/plugins"
    HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
    HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
    HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"
    HELM_NAMESPACE="default"
    

    helm repo

    Helm仓库的管理。

    # helm repo add
    
    增加仓库,以下命令为增加helm官方stable仓库,命令中stable为仓库名称,链接为仓库的Chart清单文件地址。当增加仓库时,Helm会将仓库的Chart清单文件下载到本地并存放到Kubernetes中,以后helm search、install和pull等操作都通过仓库名称到Kubernetes中查找该仓库相关的Chart包。可以注意到官方的stable仓库的地址和Helm Hub地址是不同的,两者是独立存在的,stable仓库只是众多公共仓库之一,但是是Helm官方提供的。
    
    helm repo add stable https://kubernetes-charts.storage.googleapis.com
    
    以下为官方stable仓库的清单文件,地址https://kubernetes-charts.storage.googleapis.com。可以看出就是一个个Chart包的信息,按照字母顺序排列,而且只到D开头的Chart包,所有Chart清单应该分片为多个清单文件,应该多次请求才能全部下载下来。也可以直接访问https://kubernetes-charts.storage.googleapis.com/ambassador-5.3.1.tgz将tgz包下载下来。
    ---
    以下为几个常用的仓库的添加命令。
    helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com
    helm repo add bitnami https://charts.bitnami.com/bitnami
    helm repo add aliyuncs https://apphub.aliyuncs.com
    helm repo add kong https://charts.konghq.com
    ---
    # helm repo list
    查看加到本地的仓库列表
    # helm repo list
    NAME            URL
    stable          https://kubernetes-charts.storage.googleapis.com
    aliyuncs        https://apphub.aliyuncs.com
    bitnami         https://charts.bitnami.com/bitnami
    incubator       https://kubernetes-charts-incubator.storage.googleapis.com
    kong            https://charts.konghq.com
    
    Helm v3取消了v2的local repo,Helm v3本地增加的仓库列表存放在/root/.config/helm/repositories.yaml
    # cat /root/.config/helm/repositories.yaml
    
    仓库的Chart清单应该是存储在Kubernetes的etcd中,但在/root/.cache/helm/repository存储了备份。下载的Chart包也缓存在该目录下
    # ls /root/.cache/helm/repository
    aliyuncs-index.yaml   bitnami-index.yaml    kong-index.yaml  nginx-5.1.4.tgz    tomcat-6.1.3.tgz
    ambassador-6.1.1.tgz  incubator-index.yaml  mysql-1.6.2.tgz  stable-index.yaml
    ---
    # helm repo remove
    移除本地仓库。
    helm repo remove kong
    "kong" has been removed from your repositories
    ---
    # helm repo update
    helm repo update
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "kong" chart repository
    ...Successfully got an update from the "incubator" chart repository
    ...Successfully got an update from the "aliyuncs" chart repository
    ...Successfully got an update from the "bitnami" chart repository
    ...Successfully got an update from the "stable" chart repository
    Update Complete. ⎈ Happy Helming!⎈
    ---
    # helm repo index
    根据本地目录生成Chart清单文件。和helm package命令配合用来搭建私有仓库。
    ---
    
    

    helm search
    查询Chart包,查询命令分为helm search hub和helm search repo。

    helm search hub,只从Helm Hub中查找Chart,这些Chart来自于注册到Helm Hub中的各个仓库。

    helm search repo,从所有加到本地的仓库中查找应用,这些仓库加到本地时Chart清单文件已被存放到Kubernetes中,所以查找应用时无需联网。

    # helm search hub
    从Helm Hub中查询Chart,而且只展示最新Chart版本。
    # helm search hub elasticsearch
    ---
    # helm search repo
    从本地的仓库列表中查询Chart,而且只展示Chart最新版本。注意Chart包本身有版本号,区别于Chart包中应用的版本号。
    # helm search repo elasticsearch
    NAME                     	CHART VERSION	APP VERSION	DESCRIPTION                                       
    elastic/elasticsearch    	7.15.0       	7.15.0     	Official Elastic helm chart for Elasticsearch     
    elastic/eck-operator     	1.8.0        	1.8.0      	A Helm chart for deploying the Elastic Cloud on...
    elastic/eck-operator-crds	1.8.0        	1.8.0      	A Helm chart for installing the ECK operator Cu...
    ---
    查询某个特定Chart版本。
    # helm search repo elasticsearch --version "6.8.18"
    NAME                 	CHART VERSION	APP VERSION	DESCRIPTION                                  
    elastic/elasticsearch	6.8.18       	6.8.18     	Official Elastic helm chart for Elasticsearch
    ---
    查询所有Chart版本。
    # helm search repo elasticsearch --versions
    NAME                     	CHART VERSION	APP VERSION	DESCRIPTION                                       
    elastic/elasticsearch    	7.15.0       	7.15.0     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.14.0       	7.14.0     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.13.4       	7.13.4     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.13.3       	7.13.3     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.13.2       	7.13.2     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.13.1       	7.13.1     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.13.0       	7.13.0     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.12.1       	7.12.1     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.12.0       	7.12.0     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.11.2       	7.11.2     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.11.1       	7.11.1     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.10.2       	7.10.2     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.10.1       	7.10.1     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.10.0       	7.10.0     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.9.3        	7.9.3      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.9.2        	7.9.2      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.9.1        	7.9.1      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.9.0        	7.9.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.8.1        	7.8.1      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.8.0        	7.8.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.7.1        	7.7.1      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.7.0        	7.7.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.6.2        	7.6.2      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.6.1        	7.6.1      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.6.0        	7.6.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.5.2        	7.5.2      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.5.1        	7.5.1      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.5.0        	7.5.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.4.1        	7.4.1      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.4.0        	7.4.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.3.2        	7.3.2      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.3.0        	7.3.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.2.0        	7.2.0      	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	7.1.1        	7.1.1      	Elasticsearch                                     
    elastic/elasticsearch    	7.1.0        	7.1.0      	Elasticsearch                                     
    elastic/elasticsearch    	6.8.18       	6.8.18     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.17       	6.8.17     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.16       	6.8.16     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.15       	6.8.15     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.14       	6.8.14     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.13       	6.8.13     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.12       	6.8.12     	Official Elastic helm chart for Elasticsearch     
    elastic/elasticsearch    	6.8.11       	6.8.11     	Official Elastic helm chart for Elasticsearch   
    ...
    ---
    查询某个范围的Chart版本,以下要求Chart版本号大于等于1.0.0。
    # helm search repo elasticsearch --version ">=6.8.0" --versions
    NAME                 	CHART VERSION	APP VERSION	DESCRIPTION                                  
    elastic/elasticsearch	7.15.0       	7.15.0     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.14.0       	7.14.0     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.13.4       	7.13.4     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.13.3       	7.13.3     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.13.2       	7.13.2     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.13.1       	7.13.1     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.13.0       	7.13.0     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.12.1       	7.12.1     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.12.0       	7.12.0     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.11.2       	7.11.2     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.11.1       	7.11.1     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.10.2       	7.10.2     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.10.1       	7.10.1     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.10.0       	7.10.0     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.9.3        	7.9.3      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.9.2        	7.9.2      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.9.1        	7.9.1      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.9.0        	7.9.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.8.1        	7.8.1      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.8.0        	7.8.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.7.1        	7.7.1      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.7.0        	7.7.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.6.2        	7.6.2      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.6.1        	7.6.1      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.6.0        	7.6.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.5.2        	7.5.2      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.5.1        	7.5.1      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.5.0        	7.5.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.4.1        	7.4.1      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.4.0        	7.4.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.3.2        	7.3.2      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.3.0        	7.3.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.2.0        	7.2.0      	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	7.1.1        	7.1.1      	Elasticsearch                                
    elastic/elasticsearch	7.1.0        	7.1.0      	Elasticsearch                                
    elastic/elasticsearch	6.8.18       	6.8.18     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.17       	6.8.17     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.16       	6.8.16     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.15       	6.8.15     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.14       	6.8.14     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.13       	6.8.13     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.12       	6.8.12     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.11       	6.8.11     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.10       	6.8.10     	Official Elastic helm chart for Elasticsearch
    elastic/elasticsearch	6.8.9        	6.8.9      	Official Elastic helm chart for Elasticsearch
    ...
    ---
    
    

    helm pull
    将Chart包下载到本地,缺省下载的是最新的Chart版本,并且是tgz包。

    # 先查询Chart,选择一个合适的Chart。
    helm search repo charts_name
    
    
    # 下拉Chart包。
    helm pull repo/chart_name
    
    ls
    name-version.tgz
    
    # 可以解压Chart包。
    tar zxvf name-version.tgz
    ---
    下拉指定版本。
    # helm pull bitnami/tomcat --version 2.2.2
    # ls
    tomcat-2.2.2.tgz
    ---
    下拉Chart包后直接解压为目录,而不是tgz包。
    
    # helm pull bitnami/tomcat --untar
    # ls
    tomcat
    ---
    直接从URL下拉Chart包。
    
    # helm pull https://kubernetes-charts.storage.googleapis.com/ambassador-5.3.1.tgz
    # ls
    ambassador-5.3.1.tgz
    ---
    下载Chart包到指定路径。
    
    # helm pull stable/kong -d /root/helm/
    # ls /root/helm/
    kong-0.36.6.tgz
    
    

    helm install
    安装应用,也就是部署一Chart Release实例。缺省安装最新Chart版本。其中my-web为Release名称,–set配置会覆盖Chart的values。Chart values其它文档专门介绍。

    有五种安装Chart的方式。
    1.Chart Reference:helm install myweb bitnami/tomcat
    2.Chart包路径:helm install myweb ./tomcat-6.1.3.tgz
    3.Chart包目录:helm install myweb ./tomcat
    4.URL绝对路径:helm install myweb https://charts.bitnami.com/bitnami/tomcat-6.1.3.tgz
    5.仓库URL和Chart Reference:helm install --repo https://charts.bitnami.com/bitnami/ myweb tomcat
    
    Chart Reference表示为[Repository]/[Chart],如bitnami/tomcat,Helm将在本地配置中查找名为bitnami的Chart仓库,然后在该仓库中查找名为tomcat的Chart。
    ---
    安装特定Chart版本应用。
    helm install myweb bitnami/tomcat --version 6.0.0
    ---
    将应用安装到某一命名空间,不同的命名空间Release名称可以相同。
    kubectl create namespace web-ns
    
    helm install myweb bitnami/tomcat -n web-ns
    
    helm list -n web-ns
    ---
    安装应用时,如果要覆盖Chart中的值,可以使用–set选项并从命令行传递配置。若要强制–set指定的值为字符串,请使用–set-string。–set和–set-string支持重复配置,后面(右边)的值优先级更高。
    helm install myweb bitnami/tomcat \
      --set service.type=NodePort \
      --set persistence.enabled=false
    
    ---
    
    也可以将key=values对配置在文件中,可以通过-f或者–values指定覆盖的values文件。-f或者–values支持重复指定,后面(右边)的值优先级更高。
    # helm install myweb bitnami/tomcat -f ./values.yaml
    ---
    如果一个值很大或者占用多行,很难使用–values或–set,可以使用–set-file从文件中读取单个大值。
    helm install myweb bitnami/tomcat \
      --set-file podAnnotations=./tomcat-annotations.yaml
    ---
    
    通过–dry-run模拟安装应用,会输出每个模板生成的yaml内容,可查看将要部署的渲染后的yaml,检视这些输出,判断是否与预期相符。
    # helm install my-web bitnami/tomcat \
      --dry-run \
      --set service.type=NodePort \
      --set persistence.enabled=false
    
    ---
    通过设置–wait参数,将等待所有Pod、PVC和Service以及Deployment、StatefulSet和ReplicaSet的最小Pod数都处于就绪状态后,然后才将Release标记为deployed状态,然后install命令行返回成功。等待–timeout时间,–timeout缺省为5m0s。
    helm install myweb bitnami/tomcat \
      --wait \
      --set service.type=NodePort \
      --set persistence.enabled=false
    ---
    
    设置–timeout参数,缺省为5m0s。如果超过–timeout还没有就绪,Release状态将被标记为failed,命令行返回值为1,但并不会回退提交给Kubernetes的资源,所以安装不一定失败。如下载镜像时间过长,Release的状态被置为failed,但Kubernetes仍在会继续下载镜像,所以安装最终会成功,但Release不会被重置为deployed。没有找到修改Release状态的命令。
    ---
    
    设置–atomic参数,如果安装失败,会自动清除Chart,相当于如果状态为failed时会回退所有操作,保持安装的原子性。当设置–atomic参数时,–wait参数会自动配置。
    helm install myweb bitnami/tomcat \
      --atomic --timeout=1m \
      --set service.type=NodePort \
      --set persistence.enabled=false
    
    ---
    
    

    helm list

    列出default命名空间的Release列表,只显示状态为deployed或failed的Release。
    # helm list
    
    列出某一命名空间的Release列表。
    # helm list -n web-ns
    
    列出所有命名空间的Release列表。
    # helm list --all-namespaces
    
    列出所有的Release列表,不止包括状态为deployed或failed的Release。
    # helm list -a
    
    只列出所有状态为deployed的Release列表。
    #helm list --deployed
    
    只列出所有状态为uninstalled的Release列表。
    # helm list --uninstalled
    
    只列出所有状态为failed的Release列表。
    # helm list --failed
    
    只列出所有状态为pending-install的Release列表。
    
    # 在一个终端安装Chart,会花费一些时间。
    # helm install myweb-4 bitnami/tomcat \
      --wait --timeout=10m \
      --set service.type=NodePort \
      --set persistence.enabled=false
    
    # 在另一个终端执行如下命令,只列出正在安装的Release。
    # helm list --pending
    
    按照时间顺序由早到晚列出Release。
    # helm list -d
    
    按照时间顺序由晚到早列出Release,-r翻转排序。
    # helm list -d -r
    
    

    helm uninstall

    卸载应用,也就是删除Chart Release实例。
    # helm uninstall myweb
    
    卸载某一命名空间的应用。
    # helm uninstall myweb -n web-ns
    
    卸载应用,但保留历史记录,保留历史记录主要是为了回滚操作。
    # helm uninstall myweb --keep-history
    
    

    helm test
    Chart包含了很多Kubernetes资源,而且根据values。Helm支持编写测试用例来验证Chart是否按预期工作。测试用例也有助于Chart使用者了解Chart应该做什么。

    测试用例在Helm Chart中的templates/目录,是一个pod定义,指定一个的命令来运行容器。容器应该成功退出(exit 0),测试被认为是成功的。该pod定义必须包含helm测试hook注释之一:helm.sh/hook: test-success或helm.sh/hook: test-failure。

    helm install ambassador stable/ambassador \
      --set authService.create=false \
      --set rateLimit.create=false \
      --set adminService.type=NodePort \
      --set service.type=NodePort
    
    helm pull stable/ambassador
    
    # 查看测试用例pod,helm test执行就是该pod。
    # 其实就是在容器执行命令:wget http://ambassador:80/ambassador/v0/check_ready
    cat ambassador/templates/tests/test-ready.yaml
    {{- if not .Values.daemonSet }}
    apiVersion: v1
    kind: Pod
    metadata:
      name: "{{ include "ambassador.fullname" . }}-test-ready"
      labels:
        app.kubernetes.io/name: {{ include "ambassador.name" . }}
        helm.sh/chart: {{ include "ambassador.chart" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/managed-by: {{ .Release.Service }}
      annotations:
        "helm.sh/hook": test-success
    spec:
      containers:
        - name: wget
          image: busybox
          command: ['wget']
          args:  ['{{ include "ambassador.fullname" . }}:{{ include "ambassador.servicePort" . }}/ambassador/v0/check_ready']
      restartPolicy: Never
    {{- end }}
    
    helm test ambassador
    Pod ambassador-test-ready pending
    Pod ambassador-test-ready pending
    Pod ambassador-test-ready pending
    Pod ambassador-test-ready succeeded
    NAME: ambassador
    LAST DEPLOYED: Wed Feb 12 12:56:51 2020
    NAMESPACE: default
    STATUS: deployed
    REVISION: 1
    TEST SUITE:     ambassador-test-ready
    Last Started:   Wed Feb 12 13:10:24 2020
    Last Completed: Wed Feb 12 13:10:42 2020
    Phase:          Succeeded
    NOTES:
    Congratulations! You've successfully installed Ambassador.
    
    For help, visit our Slack at https://d6e.co/slack or view the documentation online at https://www.getambassador.io.
    
    To get the IP address of Ambassador, run the following commands:
      export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services ambassador)
      export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
      echo http://$NODE_IP:$NODE_PORT
    ---
    测试时打印容器日志。
    # helm test ambassador --logs
    
    

    helm status

    显示Release的状态。
    # helm status myweb-2
    
    显示Release的某个修订版本的状态。
    # helm status myweb-2 --revision 2
    
    
    

    helm history

    显示Release的历史修订。
    # helm uninstall --keep-history myweb
    # helm list不会显示卸载了但保留历史的Release。
    # helm list
    NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION
    
    # helm list -a会显示卸载了但保留历史的Release。注意修订REVISION为1。
    # helm list -a
    NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
    myweb   default         1               2020-02-11 18:07:06.201453014 +0800 CST uninstalled     tomcat-6.1.6    9.0.30
    
    # helm history myweb
    REVISION        UPDATED                         STATUS          CHART           APP VERSION     DESCRIPTION
    1               Tue Feb 11 18:07:06 2020        uninstalled     tomcat-6.1.6    9.0.30          Uninstallation complete
    
    # helm install myweb bitnami/tomcat \
      --replace \
      --set persistence.enabled=false
    
    # helm list只显示生效的Release。注意修订REVISION为2
    # helm list
    NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
    myweb   default         2               2020-02-11 17:55:47.971239954 +0800 CST deployed        tomcat-6.1.6    9.0.30
    
    # helm history myweb
    REVISION        UPDATED                         STATUS          CHART           APP VERSION     DESCRIPTION
    1               Tue Feb 11 16:46:37 2020        superseded      tomcat-6.1.6    9.0.30          superseded by new release
    2               Tue Feb 11 17:55:47 2020        deployed        tomcat-6.1.6    9.0.30          Install complete
    
    

    helm rollback

    helm get

    # helm get manifest
    # helm get manifest myweb
    显示Release的所有的Kubernetes资源清单,注释标明了该资源生成于那个模板yaml文件。
    
    # helm get all
    显示Release的所涉及模板变量的值。
    # helm get all myweb --template {{.Release.Name}}
    

    helm create
    创建一个模板Chart,会根据给定的Chart名称生成一个目录以及该Chart的一些样例文件。

    helm create foo
    Creating foo
    
    ls
    foo
    
    tree foo
    foo
    ├── charts
    ├── Chart.yaml
    ├── templates
    │   ├── deployment.yaml
    │   ├── _helpers.tpl
    │   ├── ingress.yaml
    │   ├── NOTES.txt
    │   ├── serviceaccount.yaml
    │   ├── service.yaml
    │   └── tests
    │       └── test-connection.yaml
    └── values.yaml
    
    3 directories, 9 files
    
    

    我们可以使用create命令创建一个模板,然后根据该模板快速开发。

    helm show
    显示Chart包的各种信息,Chart包中的Chart.yaml, values.yaml和README.md文件包含了Chart重要关键信息,可以通过helm show命令行显示这些文件的内容,方便了解Chart关键内容。

    helm show chart
    显示Chart.yaml信息,该文件描述了Chart的版本,描述,开发者等信息。
    
    helm show chart bitnami/tomcat
    apiVersion: v1
    appVersion: 9.0.30
    description: Chart for Apache Tomcat
    home: http://tomcat.apache.org
    icon: https://bitnami.com/assets/stacks/tomcat/img/tomcat-stack-110x117.png
    keywords:
    - tomcat
    - java
    - http
    - web
    - application server
    - jsp
    maintainers:
    - email: containers@bitnami.com
      name: Bitnami
    name: tomcat
    sources:
    - https://github.com/bitnami/bitnami-docker-tomcat
    version: 6.1.3
    ---
    helm show values
    显示values.yaml信息,该文件描述了Chart模板中各个可以覆盖的参数,这些参数都可以在安装Chart时被命令行参数覆盖。
    
    helm show values bitnami/tomcat
    ## Global Docker image parameters
    ## Please, note that this will override the image parameters, including dependencies, configured to use the global value
    ## Current available global Docker image parameters: imageRegistry and imagePullSecrets
    ##
    # global:
    #   imageRegistry: myRegistryName
    #   imagePullSecrets:
    #     - myRegistryKeySecretName
    #   storageClass: myStorageClass
    
    ## Bitnami Tomcat image version
    ## ref: https://hub.docker.com/r/bitnami/tomcat/tags/
    ##
    image:
      registry: docker.io
      repository: bitnami/tomcat
      tag: 9.0.30-debian-9-r9
    ...
    
    

    helm template
    渲染Chart模板并打印输出,并不实际安装。和helm get manifest类似。

    helm template myweb bitnami/tomcat \
      --set service.type=NodePort \
      --set persistence.enabled=false
    

    helm dependency

    管理Chart依赖。
    helm dependency list
    
    列出Chart申明的所有依赖的列表。
    helm dependency update
    
    更新Chart申明的所有依赖符合要求的最新版本,更新的依赖的tgz包文件会放到charts路径下。更新之前会先更新所有的仓库。
    ls kong/charts/
    postgresql
    helm dependency update kong
    
    

    helm lint
    Helm运行一系列测试以验证Chart格式是否正确。如果遇到会导致Chart安装失败的事件,将发出[ERROR]消息。如果遇到违反约定或推荐的问题,将发出[WARNING]消息。

    helm lint tomcat/
    ==> Linting tomcat/
    
    1 chart(s) linted, 0 chart(s) failed
    

    helm package
    将目录结构的Chart打包成带版本号tgz格式的Chart包。和helm repo index配合用来搭建私有仓库。

    helm pull bitnami/tomcat --untar --version 6.1.6
    
    ls
    tomcat
    
    helm package tomcat
    Successfully packaged chart and saved it to: /root/helm/tomcat-6.1.6.tgz
    
    ls
    tomcat  tomcat-6.1.6.tgz
    ---
    在打包时,设置覆盖的values,此时Chart包中values.yaml文件对应的key的键值会被自动替换为命令行中的values。
    
    helm package tomcat \
      --set service.type=NodePort \
      --set persistence.enabled=false
    
    
  • 相关阅读:
    Java hutool/java 常用方法
    版本控制工具 TortoiseGit 基本配置
    SpringBlade 码云上我自己的fork的仓库简单使用
    版本控制工具 Git SourceTree SSH 连接码云
    版本控制工具 Git SourceTree 报错 fatal: could not read Username for 'https://gitee.com': No such file or directory
    在充电桩联网部署方案中4G DTU的优势是什么
    4G DTU模块和串口设备连接的方式
    4g物联网模块的原理
    4G DTU采用的4G通信模块介绍
    4G DTU数据传输终端的功能介绍
  • 原文地址:https://www.cnblogs.com/davis12/p/15469167.html
Copyright © 2011-2022 走看看