簡體   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