快速創(chuàng)建一個chart模板,helm create mychart
,執(zhí)行命令后本地生成一個mychart目錄.
創(chuàng)新互聯(lián)自2013年起,先為蓬萊等服務建站,蓬萊等地企業(yè),進行企業(yè)商務咨詢服務。為蓬萊企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。
一個最小的chart目錄,只需要包含一個Chart.yaml,和templates目錄下一個k8s資源文件.如:
# mychart/Chart.yaml
apiVersion: v1
appVersion: 2.9.0
version: 1.1.1
# mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mychart-configmap
data:
myvalue: "Hello World"
- go-template雙
- sprig
模板引用方式,{{ .Release.Name }}
, 通過雙括號注入,小數(shù)點開頭表示從最頂層命名空間引用.
# Release, release相關(guān)屬性
# Chart, Chart.yaml文件中定義的內(nèi)容
# Values, values.yaml文件中定義的內(nèi)容
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
drink: {{ .Values.favorite.drink | repeat 5 | quote }}
food: {{ .Values.favorite.food | upper | quote }}
{{ if PIPELINE }}
# Do something
{{ else if OTHER PIPELINE }}
# Do something else
{{ else }}
# Default case
{{ end }}
操作符, and/eq/or/not
{{/* include the body of this if statement when the variable .Values.fooString exists and is set to "foo" */}}
{{ if and .Values.fooString (eq .Values.fooString "foo") }}
{{ ... }}
{{ end }}
{{/* do not include the body of this if statement because unset variables evaluate to false and .Values.setVariable was negated with the not function. */}}
{{ if or .Values.anUnsetVariable (not .Values.aSetVariable) }}
{{ ... }}
{{ end }}
{{- if ...}}
的方式消除此空行.如:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- if eq .Values.favorite.drink "coffee"}}
mug: true
{{- end}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
{{- end }}
range命令實現(xiàn)循環(huán),如:
# values.yaml
favorite:
drink: coffee
food: pizza
pizzaToppings:
- mushrooms
- cheese
- peppers
- onions
#configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
toppings: |-
{{- range .Values.pizzaToppings }}
- {{ . }}
# .表示range的命令空間下的取值
{{- end }}
{{- range $key, $val := .Values.favorite }}
{{ $key }}: {{ $val | quote }}
{{- end}}
ApiVersion: v1
Kind: ConfigMap
Metadata:
name: {{ .Release.Name }}-configmap
Data:
myvalue: "Hello World"
# 由于下方的with語句引入相對命令空間,無法通過.Release引入,提前定義relname變量
{{- $relname := .Release.Name -}}
{{- with .Values.favorite }}
food: {{ .food }}
release: {{ $relname }}
# 或者可以使用$符號,引入全局命名空間
release: {{ $.Release.Name }}
{{- end }}
公共模板,define定義,template引入,在templates目錄中默認下劃線_開頭的文件為公共模板(_helpers.tpl)
# _helpers.tpl文件
{{- define "mychart.labels" }}
labels:
generator: helm
date: {{ now | htmlDate }}
{{- end }}
# configmap.yaml文件
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
{{- template "mychart.labels" }}
data:
myvalue: "Hello World"
template語句的升級版本include,template是語句無法在后面接管道符來對引入變量做定義,
include實現(xiàn)了此功能.
# _helpers.tpl文件
{{- define "mychart.app" -}}
app_name: {{ .Chart.Name }}
app_version: "{{ .Chart.Version }}+{{ .Release.Time.Seconds }}"
{{- end -}}
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
labels:
{{- include "mychart.app" . | nindent 4 }}
data:
myvalue: "Hello World"
{{- range $key, $val := .Values.favorite }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- include "mychart.app" . | nindent 2 }}
# 如果使用template只能手動空格,不能使用管道后的nindent函數(shù)來做縮進
helm install stable/drupal --set image=my-registry/drupal:0.1.0 --set livenessProbe.exec.command=[cat,docroot/CHANGELOG.txt] --set livenessProbe.httpGet=null<br/>
,livenessProbe在values.yaml中定義了httpGet,需要手動設置為null,然后設置exec的探針.
網(wǎng)站欄目:helm模板文件chart編寫語法詳解
瀏覽地址:http://m.rwnh.cn/article4/jcgioe.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google、虛擬主機、網(wǎng)站設計公司、電子商務、動態(tài)網(wǎng)站、外貿(mào)網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)