繁体   English   中英

Helm 从 values.yaml 导入 map 和数组

[英]Helm import map and array from values.yaml

'我使用helm create <chart-name>创建了一个 helm 图表

在 values.yaml 我添加了以下 map 和数组

nodeSelector:
  instance-type: "re"

tolerations:
  - key: "re"
    operator: "Equal"
    value: "true"
    effect: "NoSchedule"

我正在尝试在模板/部署中导入这些。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]

我尝试了许多其他方法,但似乎都没有。 我的猜测是阵列和 map 我需要在部署中进行更改。yaml 但我不知道如何

您似乎错误地缩进了affinitynodeSelectortolerations

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`
      ...

以下键必须位于容器的同一级别,因此缩进额外的两个空格应该可以解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM