1. 模板介紹
首先,放上此模板鏈接:
https://github.com/ygqygq2/charts/tree/master/mod-chart
此chart可當作POD單image的通用模板,只需要使用sed
替換下chart名,並修改下README.md
和NOTES.txt
就可以了。下文,我通過複製此chart成example-chart
來作示範說明。
[root@master1 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
[root@master1 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 's@mod-chart@example-chart@g' *.*
sed -i 's@mod-chart@example-chart@g' 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
這裏提幾個常用的地方:
- 使用2個空格作縮進;
- 確認數字爲字符類型時,使用雙引號引起來;
- 爲了迎合helm3的規範,空定義最好將相關符號補上:
string: ""
list: []
map: {}
沒什麼特殊要求,一般需要修改的地方有image
、service
、healthCheck
、persistentVolume.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
未完待補