Helm 从 values.yaml 导入地图和数组
Helm import map and array from values.yaml
'我使用 helm create <chart-name>
创建了一个 helm chart
在values.yaml中我添加了下面的映射和数组
nodeSelector:
instance-type: "re"
tolerations:
- key: "re"
operator: "Equal"
value: "true"
effect: "NoSchedule"
我正在尝试将这些导入 templates/deployment.yaml 那里的配置看起来有正确的缩进
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ include "dummy-app.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "dummy-app.name" . }}
helm.sh/chart: {{ include "dummy-app.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "dummy-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "dummy-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
log_group_name: {{ .Values.logging.log_group_name }}
annotations:
jitsi.io/metrics_path: {{.Values.service.metricsPath | default "/actuator/prometheus" | quote }}
jitsi.io/scrape_port: {{.Values.service.actuatorPort | default "8083" | quote }}
jitsi.io/should_be_scraped: {{.Values.service.shouldScrapp | default "true" | quote}}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{.Values.service.targetPort}}
protocol: TCP
- name: http-actuator
containerPort: {{.Values.service.actuatorPort}}
protocol: TCP
livenessProbe:
httpGet:
path: /actuator/health
port: http-actuator
initialDelaySeconds: 30
readinessProbe:
httpGet:
path: /actuator/health
port: http-actuator
initialDelaySeconds: 30
env:
- name: PROFILES
value: {{ required "Environment name is required." .Values.env.environment | quote }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
当我 运行 我得到:
Error: validation failed: error validating "": error validating data: [ValidationError(Deployment.spec.template): unknown field "nodeSelector" in io.k8s.api.core.v1.PodTemplateSpec, ValidationError(Deployment.spec.template): unknown field "tolerations" in io.k8s.api.core.v1.PodTemplateSpec]
我尝试了许多其他方法,但 none 似乎有效。我的猜测是数组和映射 deployment.yaml 我需要更改一些内容,但我不知道如何更改
您的缩进似乎有误 affinity
、nodeSelector
和 tolerations
:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ include "dummy-app.fullname" . }}
labels:
...
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
...
template:
metadata:
labels:
...
annotations:
...
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
...
livenessProbe:
...
readinessProbe:
...
env:
...
resources:
...
nodeSelector: # <<< this are at the same level of `spec`
...
affinity: # <<< this are at the same level of `spec`
...
tolerations: # <<< this are at the same level of `spec`
...
以下键必须在同一级别的容器中,因此缩进额外的两个空格应该可以解决您的问题。
'我使用 helm create <chart-name>
在values.yaml中我添加了下面的映射和数组
nodeSelector:
instance-type: "re"
tolerations:
- key: "re"
operator: "Equal"
value: "true"
effect: "NoSchedule"
我正在尝试将这些导入 templates/deployment.yaml 那里的配置看起来有正确的缩进
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ include "dummy-app.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "dummy-app.name" . }}
helm.sh/chart: {{ include "dummy-app.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "dummy-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "dummy-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
log_group_name: {{ .Values.logging.log_group_name }}
annotations:
jitsi.io/metrics_path: {{.Values.service.metricsPath | default "/actuator/prometheus" | quote }}
jitsi.io/scrape_port: {{.Values.service.actuatorPort | default "8083" | quote }}
jitsi.io/should_be_scraped: {{.Values.service.shouldScrapp | default "true" | quote}}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{.Values.service.targetPort}}
protocol: TCP
- name: http-actuator
containerPort: {{.Values.service.actuatorPort}}
protocol: TCP
livenessProbe:
httpGet:
path: /actuator/health
port: http-actuator
initialDelaySeconds: 30
readinessProbe:
httpGet:
path: /actuator/health
port: http-actuator
initialDelaySeconds: 30
env:
- name: PROFILES
value: {{ required "Environment name is required." .Values.env.environment | quote }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
当我 运行 我得到:
Error: validation failed: error validating "": error validating data: [ValidationError(Deployment.spec.template): unknown field "nodeSelector" in io.k8s.api.core.v1.PodTemplateSpec, ValidationError(Deployment.spec.template): unknown field "tolerations" in io.k8s.api.core.v1.PodTemplateSpec]
我尝试了许多其他方法,但 none 似乎有效。我的猜测是数组和映射 deployment.yaml 我需要更改一些内容,但我不知道如何更改
您的缩进似乎有误 affinity
、nodeSelector
和 tolerations
:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ include "dummy-app.fullname" . }}
labels:
...
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
...
template:
metadata:
labels:
...
annotations:
...
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
...
livenessProbe:
...
readinessProbe:
...
env:
...
resources:
...
nodeSelector: # <<< this are at the same level of `spec`
...
affinity: # <<< this are at the same level of `spec`
...
tolerations: # <<< this are at the same level of `spec`
...
以下键必须在同一级别的容器中,因此缩进额外的两个空格应该可以解决您的问题。