zoukankan      html  css  js  c++  java
  • k8s~helm构建一个应用

    三个概念

    1. chart:包含了创建Kubernetes的一个应用实例的必要信息
    2. config:包含了应用发布配置信息
    3. release:是一个chart及其配置的一个运行实例

    建立一个helm charts

    helm create hello-world
    
    • Chart.yaml 用于描述这个Chart的相关信息,包括名字、描述信息以及版本等。
      仅仅是一些简单的文本描述

    • values.yaml 用于存储 templates 目录中模板文件中用到变量的值。

    • NOTES.txt 用于介绍 Chart 部署后的一些信息,例如:如何使用这个 Chart、列出缺省的设置等。

    • Templates 目录下是 YAML 文件的模板,该模板文件遵循 Go template 语法。

    Templates 目录下 YAML 文件模板的值默认都是在 values.yaml 里定义的,比如在 deployment.yaml 中定义的容器镜像。
    image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
    其中的 .Values.image.repository 的值就是在 values.yaml 里定义的 nginx,.Values.image.tag 的值就是 stable。
    以上两个变量值是在 create chart 的时候就自动生成的默认值,你可以根据实际情况进行修改。实际上都是静态文本,只在是执行的时候才被解析.

    构建一个helm应用

    打开 Chart.yaml,可以看到内容如下,配置名称和版本

    apiVersion: v1
    appVersion: "1.0"
    description: A Helm chart for Kubernetes
    name: mychart
    version: 0.1.0
    

    编辑 values.yaml,它默认会在 Kubernetes 部署一个 Nginx。下面是 mychart 应用的 values.yaml 文件的内容:

    $ cat mychart/values.yaml
    # Default values for mychart.
    # This is a YAML-formatted file.
    # Declare variables to be passed into your templates.
    
    replicaCount: 1
    
    image:
      repository: nginx
      tag: stable
      pullPolicy: IfNotPresent
    
    service:
      type: ClusterIP
      port: 80
    
    ingress:
      enabled: false
      annotations: {}
        # kubernetes.io/ingress.class: nginx
        # kubernetes.io/tls-acme: "true"
      path: /
      hosts:
        - chart-example.local
      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
    
    nodeSelector: {}
    
    tolerations: []
    
    affinity: {}
    

    检查模块配置

    $ helm lint hello-world/
    

    打包

    helm package hello-world
    helm package mychart --debug #显示详细信息
    

    启动helm本地仓库(helm3已被移除)

    helm serve  --repo-path /data/helm/repository/ --url http://172.17.0.22:8879/charts/ &
    

    仓库刷新和查询应用

    $ helm repo update
    $ helm search mychart
    NAME         	CHART VERSION	APP VERSION	DESCRIPTION
    local/hello-world	0.1.0        	1.0        	A Helm chart for Kubernetes
    

    在 Kubernetes 中部署应用

    Chart 被发布到仓储后,就可以通过 helm install 命令部署该 Chart。

    helm install  hello local/hello-world
    

    查看Release的状态信息

     helm status wordpress
    

    升级charts

    helm upgrade  wordpress stable/wordpress
    helm upgrade --install --force hello-world ./hello.tgz --namespace test  # 也可以指定命名空间和它的taz包
    

    回滚到上一个版本

    helm rollback hello-world 1 # 向上归滚一个版本
    
  • 相关阅读:
    Android SDK Manager和AVD Manager使用
    Android Studio 学习之 Android SDK快速更新
    Windows10远程报错:由于CredSSP加密Oracle修正
    电商促销优惠规则业务分析建模
    关于分库分表最全的一篇文章
    根据自增ID生成不重复序列号
    【转】 Pro Android学习笔记(五八):Preferences(2):CheckBoxPreference
    【转】 Pro Android学习笔记(五七):Preferences(1):ListPreference
    【转】 Pro Android学习笔记(五六):配置变化
    【转】 Pro Android学习笔记(五五):调试和分析(3):adb命令、模拟器控制台和StrictMode
  • 原文地址:https://www.cnblogs.com/lori/p/12671586.html
Copyright © 2011-2022 走看看