手把手教你写一个通用的helm chart

[TOC]

1. 模板介绍

首先,放上此模板链接:

https://github.com/ygqygq2/charts/tree/master/mod-chart

此chart可当作POD单image的通用模板,只需要使用sed替换下chart名,并修改下README.mdNOTES.txt就可以了。下文,我通过复制此chart成example-chart来作示范说明。

[[email protected] mod-chart]# tree
.
├── Chart.yaml
├── README.md
├── templates
│?? ├── configmap.yaml
│?? ├── deployment-statefulset.yaml
│?? ├── _helpers.tpl
│?? ├── ingress.yaml
│?? ├── NOTES.txt
│?? ├── pvc.yaml
│?? ├── secret.yaml
│?? ├── service-headless.yaml
│?? └── service.yaml
└── values.yaml

1 directory, 12 files
[[email protected] mod-chart]# helm3 lint --strict .
1 chart(s) linted, 0 chart(s) failed

2. 新chart制作

注:
下文中文件内容我保留,只加注释。
注释中需要修改的地方 [*] 标记为必选,[-] 标识为可选。

2.1 目录准备

将模板mod-chart复制成example-chart,并作内容替换。

rsync -avz mod-chart/ example-chart/
cd example-chart/
sed -i ‘[email protected]@[email protected]‘ *.*
sed -i ‘[email protected]@[email protected]‘ templates/*.*

2.2 修改Chart.yaml

vim Chart.yaml

apiVersion: v1  # 当前helm api版本,不需要修改
appVersion: 1.14.2  # 此处为你应用程序的版本号 [*]
description: Chart for the nginx server  # 介绍此chart是干嘛的,按需求修改
engine: gotpl  # go模板引擎,不需要修改 [-]
name: example-chart  # 模板名,对应目录名 [*]
version: 1.0.0  # 此chart版本号 [*]
home: http://www.nginx.org  # 应用程序官网 [*]
icon: https://bitnami.com/assets/stacks/nginx/img/nginx-stack-220x234.png  # 应用程序logo地址 [*]
keywords:  # 关键字列表 [*]
- nginx
- http
- web
- www
- reverse proxy
maintainers:  # 维护人员列表 [*]
- email: [email protected]
  name: Chinge Yang
sources:  # 应用程序来源 [-]
- https://github.com/bitnami/bitnami-docker-nginx

2.3 修改values.yaml

因为values.yaml设置涉及到yaml格式,yaml文件格式说明可以看这篇文章:

http://www.ruanyifeng.com/blog/2016/07/yaml.html

这里提几个常用的地方:

  1. 使用2个空格作缩进;
  2. 确认数字为字符类型时,使用双引号引起来;
  3. 为了迎合helm3的规范,空定义最好将相关符号补上:
    string: ""
    list: []
    map: {}

没什么特殊要求,一般需要修改的地方有imageservicehealthCheckpersistentVolume.mountPaths

# Default values for mod-chart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

## 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: ""
  imagePullSecrets: []
#     - myRegistryKeySecretName

statefulset:
  enabled: false

## String to partially override fullname template (will maintain the release name)
##
nameOverride: ""

## String to fully override fullname template
##
fullnameOverride: ""

## By default deploymentStrategy is set to rollingUpdate with maxSurge of 25% and maxUnavailable of 25% .
## You can change type to `Recreate` or can uncomment `rollingUpdate` specification and adjust them to your usage.
deploymentStrategy: {}
  # rollingUpdate:
  #   maxSurge: 25%
  #   maxUnavailable: 25%
  # type: RollingUpdate

# 副本个数
replicaCount: 1

# 容器image及tag
image:
  registry: docker.io
  repository: bitnami/nginx
  tag: latest
  pullPolicy: IfNotPresent  # IfNotPresent: 有则不拉(减少流量和操作步骤),Always: 不管tag总拉(适合tag不变时更新)
  pullSecrets: []
  #  - private-registry-key

service:
  type: ClusterIP  # 一般不用修改
  ingressPort: 8080
  ports:
    web:  # 多端口暴露时,复制一段
      port: 8080  # Service port number for client-a port.
      protocol: TCP  # Service port protocol for client-a port.

## env set
## ref: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
env: []
#  - name: DEMO_GREETING
#    value: "Hello from the environment"
#  - name: DEMO_FAREWELL
#    value: "Such a sweet sorrow"

## command set
startCommand: []
#  - "java -Xdebug -Xnoagent -Djava.compiler=NONE"
#  - "-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
#  - "-Djava.security.egd=file:/dev/urandom"
#  - "-jar /test.jar"
#  - "-Duser.timezone=GMT+08"

## Enable configmap and add data in configmap
config:
  enabled: false
  subPath: ""
  mountPath: /conf
  data: {}
## 以下示例,挂载文件至 /conf/app.conf
#  enabled: true
#  mountPath: /conf
#  subPath: app.conf
#  data:
#    app.conf: |-
#      appname = example-chart

## To use an additional secret, set enable to true and add data
secret:
  enabled: false
  mountPath: /etc/secret-volume
  subPath: ""
  readOnly: true
  data: {}
## 以下示例,挂载文件至 /etc/secret-volume
#  enabled: true
#  mountPath: /conf
#  data:
#    app.conf: |-
#      appname = example-chart

## liveness and readiness
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
healthCheck:
  enabled: true
  type: tcp  # http/tcp
  port: http  # 上面的端口名或端口
  httpPath: ‘/‘  # http时必须设置
  livenessInitialDelaySeconds: 10  # 初始延迟秒数
  livenessPeriodSeconds: 10  # 检测周期,默认值10,最小为1
  readinessInitialDelaySeconds: 10  # 初始延迟秒数
  readinessPeriodSeconds: 10   # 检测周期,默认值10,最小为1

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

## Node labels and tolerations for pod assignment
### ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector
### ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#taints-and-tolerations-beta-feature
labels: {}
podAnnotations: {}
nodeSelector: {}
tolerations: []
affinity: {}
annotations: {}

## Enable persistence using Persistent Volume Claims
## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
persistentVolume:   # 是否存储持久化
  enabled: false
  ## If defined, storageClassName: <storageClass>
  ## If set to "-", storageClassName: "", which disables dynamic provisioning
  ## If undefined (the default) or set to null, no storageClassName spec is
  ##   set, choosing the default provisioner.  (gp2 on AWS, azure-disk on
  ##   Azure, standard on GKE, AWS & OpenStack)
  ##
  storageClass: "-"
  accessMode: ReadWriteOnce
  annotations: {}
  #   helm.sh/resource-policy: keep
  size: 1Gi  # 大小
  existingClaim: {}  # 使用已存在的pvc
  mountPaths: []
  #  - name: data-storage
  #    mountPath: /config
  #    subPath: config
  #  - name: data-storage
  #    mountPath: /data
  #    subPath: data

ingress:  # 是否使用nginx暴露域名或端口
  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

## Add init containers. e.g. to be used to give specific permissions for data
## Add your own init container or uncomment and modify the given example.
initContainers: []

## Prometheus Exporter / Metrics
##
metrics:
  enabled: false
  image:
    registry: docker.io
    repository: nginx/nginx-prometheus-exporter
    tag: 0.1.0
    pullPolicy: IfNotPresent
    ## Optionally specify an array of imagePullSecrets.
    ## Secrets must be manually created in the namespace.
    ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
    ##
    pullSecrets: []
    #   - myRegistrKeySecretName
  ## Metrics exporter pod Annotation and Labels
  podAnnotations:
    # prometheus.io/scrape: "true"
    # prometheus.io/port: "9113"
    ## Metrics exporter resource requests and limits
    ## ref: http://kubernetes.io/docs/user-guide/compute-resources/
    ##
  resources: {}

## Uncomment and modify this to run a command after starting the core container.
## ref: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
lifecycle: {}
  # preStop:
  #   exec:
  #     command: ["/bin/bash","/pre-stop.sh"]
  # postStart:
  #   exec:
  #     command: ["/bin/bash","/post-start.sh"]

## Deployment additional volumes.
deployment:
  additionalVolumes: []

## init containers
## ref: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
## Add init containers. e.g. to be used to give specific permissions for data
## Add your own init container or uncomment and modify the given example.
initContainers: {}
#  - name: fmp-volume-permission
#    image: busybox
#    imagePullPolicy: IfNotPresent
#    command: [‘chown‘,‘-R‘, ‘200‘, ‘/extra-data‘]
#    volumeMounts:
#      - name: extra-data
#        mountPath: /extra-data

## Additional containers to be added to the core pod.
additionalContainers: {}
#  - name: my-sidecar
#    image: nginx:latest
#  - name: lemonldap-ng-controller
#    image: lemonldapng/lemonldap-ng-controller:0.2.0
#    args:
#      - /lemonldap-ng-controller
#      - --alsologtostderr
#      - --configmap=$(POD_NAMESPACE)/lemonldap-ng-configuration
#    env:
#      - name: POD_NAME
#        valueFrom:
#          fieldRef:
#            fieldPath: metadata.name
#      - name: POD_NAMESPACE
#        valueFrom:
#          fieldRef:
#            fieldPath: metadata.namespace
#    volumeMounts:
#    - name: copy-portal-skins
#      mountPath: /srv/var/lib/lemonldap-ng/portal/skins

未完待补

原文地址:https://blog.51cto.com/ygqygq2/2425441

时间: 2024-07-30 03:20:19

手把手教你写一个通用的helm chart的相关文章

大神手把手教你写一个页面模板引擎,只需20行Javascript代码!

只用20行Javascript代码就写出一个页面模板引擎的大神是AbsurdJS的作者,下面是他分享的全文,转需. 不知道你有木有听说过一个基于Javascript的Web页面预处理器,叫做AbsurdJS.我是它的作者,目前我还在不断地完善它.最初我只是打算写一个CSS的预处理器,不过后来扩展到了CSS和HTML,可以用来把Javascript代码转成CSS和HTML代码.当然,由于可以生成HTML代码,你也可以把它当成一个模板引擎,用于在标记语言中填充数据. 于是我又想着能不能写一些简单的代

手把手教你写一个java的orm(二)

创建映射关系 ? 想要实现一个orm的功能,我觉得就是要将class和数据库中的表创建映射关系.把class的名称和表的名称,class属性名称和表的字段名称,属性类型与表的字段类型一一对应起来.可以通过配置文件,注解等等各种方式实现这个映射关系. 需要的依赖 ? 因为编写配置文件总是一件十分繁琐的事情,所以我决定使用注解的方式来实现这个映射.在项目刚开始写的时候我用的是自定义注解的方法.自己规定一套注解,后来觉得这样没有太大的必要,因为已经有jpa里的一套注解.所以直接用就好了.所以添加依赖:

手把手教你写一个RN小程序!

时间过得真快,眨眼已经快3年了! 1.我的第一个App 还记得我14年初写的第一个iOS小程序,当时是给别人写的一个单机的相册,也是我开发的第一个完整的app,虽然功能挺少,但是耐不住心中的激动啊,现在我开始学react native,那么现在对于react native也算是有所了解了,就用网上的接口开发一个小程序,现在带大家来写这个程序!接口是用看知乎的API,简简单单的只有get,可以从这里入门,也算是带大家入门吧,过后我会把源代码放在我的github上,前期项目肯定特别简陋,后面慢慢来优

手把手教你写一个java的orm(完)

生成sql:select 上一篇讲了怎样生成一个sql中where的一部分,之后我们要做事情就简单很多了,就只要像最开始一样的生成各种sql语句就好了,之后只要再加上我们需要的条件,一个完整的sql就顺利的做好了. 现在我们开始写生成查询语句的sql.一个查询语句大致上是这样的: SELECT name, id, create_date, age, mark, status FROM user 这里可以看出来,一个基础的查询语句基本上就是一个 SELECT 后面加上需要查询的字段,跟上 FROM

手把手教你写一个用pytorch实现的Lenet5

最近为了实现HR-net在学习pytorch,然后突然发现这个框架简直比tensorflow要方便太多太多啊,我本来其实不太喜欢python,但是这个框架使用的流畅性真的让我非常的喜欢,下面我就开始介绍从0开始编写一个Lenet并用它来训练cifar10. 1.首先需要先找到Lenet的结构图再考虑怎么去实现它,在网上找了一个供参考 2.需要下载好cifar-10的数据集,在pytorch下默认的是下载cifar-10-python版本的,由于官网速度较慢,我直接提供度娘网盘的链接:链接:htt

手把手教你写专利申请书/怎样申请专利

手把手教你写专利申请书·怎样申请专利 摘要小前言(一)申请前的准备工作    1.申请前查询    2.其它方面的考虑    3.申请文件准备(二)填写专利申请系列文档    1.实际操作步骤    2.详细操作    3.经验分享.注意事项(三)关于费用(四)其它的话參考资源提示常见问题的问与答 摘要: 怎样写好专利申请?由于非常多专利申请人都是第一次申请,因此,可能有一种神奇和些许恐惧.本文写的是怎样写专利申请书,手把手教你写专利申请并提供申请专利时的注意事项,专利申请费用及费用减缓等相关參

手把手教你写专利申请书/如何申请专利

http://blog.csdn.net/johnsuna/article/details/3492145 手把手教你写专利申请书·如何申请专利 摘要小前言(一)申请前的准备工作    1.申请前查询    2.其他方面的考虑    3.申请文件准备(二)填写专利申请系列文档    1.实际操作步骤    2.具体操作    3.经验分享.注意事项(三)关于费用(四)其他的话参考资源提示常见问题的问与答 摘要: 如何写好专利申请?由于很多专利申请人都是第一次申请,因此,可能有一种神秘和些许恐惧.

手把手教你写网络爬虫(3):开源爬虫框架对比

手把手教你写网络爬虫(3) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 介绍 大家好!我们从今天开始学习开源爬虫框架Scrapy,如果你看过<手把手>系列的前两篇,那么今天的内容就非常容易理解了.细心的读者也许会有疑问,为什么不学出身名门的Apache顶级项目Nutch,或者人气飙升的国内大神开发的Pyspider等框架呢?原因很简单,我们来看一下主流爬虫框架在GitHub上的活跃度: Project Language Star Watch Fork Nutch Java 1

Android开发之手把手教你写ButterKnife框架(二)

欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52664112 本文出自:[余志强的博客] 上一篇博客Android开发之手把手教你写ButterKnife框架(一)我们讲了ButterKnife是什么.ButterKnife的作用和功能介绍以及ButterKnife的实现原理. 本篇博客主要讲在android studio中如何使用apt. 一.新建个项目, 然后创建一个module名叫processor 新建m