'我已经创建了一个头盔图,使用 helm create <chart-name>
在values.yaml中,我添加了以下地图和数组。
nodeSelector:
instance-type: "re"
tolerations:
- key: "re"
operator: "Equal"
value: "true"
effect: "NoSchedule"
我试图在templatesdeployment.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: SPRING_PROFILES_ACTIVE
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]
我试了很多其他的方法,但似乎都不行 我猜测是数组和地图,我需要修改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`
...
下面的键必须在同一层次的容器中,所以用额外的两个空格缩进应该可以解决你的问题。