【问题标题】:error converting YAML to JSON: mapping values are not allowed in this context将 YAML 转换为 JSON 时出错:此上下文中不允许映射值
【发布时间】:2021-07-23 13:49:23
【问题描述】:

我正在使用 helm3。 我的 kubernetes 部署在下面的 43 行代码中崩溃了。

控制台出错:将 YAML 转换为 JSON 时出错:此上下文中不允许映射值

yaml lint 是这样说的: (): 在第 43 行第 19 列扫描纯标量时发现意外的 ':'

那行有什么问题?

错了:

- image: {{ printf "%s/%s:%s" .Values.dockerRegistry .Values.dockerImage .Values.version }}



  apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "deploy_name" . }}
  namespace: {{ .Release.Namespace }}
spec:
  replicas: {{ .Values.replicas.min }}
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}
        team: {{ .Values.meta.team }}
        env: {{ .Values.env }}
        version: {{ .Values.version }}
        revision: {{ .Release.Revision | quote }}
        json_logs: "true"
        commit_hash: {{ .Values.commitHash }}
      annotations:
        prometheus.io/port: {{ .Values.ports.application | quote }}
        prometheus.io/path: {{ .Values.prometheus.path | quote }}
        prometheus.io/scrape: {{ .Values.prometheus.scrape | quote }}
        prometheus.io/scheme: {{ .Values.prometheus.scheme | quote }}
        host/url: {{ .Values.url | quote }}
        host.net/owner: {{ .Values.meta.owner | quote }}
        host.net/system: {{ .Values.meta.team | quote }}
        sidecar.istio.io/rewriteAppHTTPProbers: "true"
    spec:
      imagePullSecrets:
      - name: gitlab
      hostAliases:
      - ip: 0.0.0.0
        hostnames:
        - host
        - host
      - ip: 0.0.0.0
        hostnames:
        - host
      containers:
      - image: {{ printf "%s/%s:%s" .Values.dockerRegistry .Values.dockerImage .Values.version }}
        imagePullPolicy: Always
        name: website
        ports:
        - containerPort: {{  .Values.ports.application }}
        envFrom:
        - configMapRef:
            name: {{ template "config_map_name" . }}
        - secretRef:
            name: {{ template "secret_name" . }}
        resources:
          limits:
            cpu: 2
            memory: 4Gi
          requests:
            cpu: 350m
            memory: 2Gi
        livenessProbe:
          httpGet:
            path: /healthz
            port: {{ .Values.ports.application }}
          initialDelaySeconds: 20
          periodSeconds: 3
          failureThreshold: 10
        readinessProbe:
          httpGet:
            path: /readyz
            port: {{ .Values.ports.application }}
          initialDelaySeconds: 20
          periodSeconds: 3

【问题讨论】:

  • 试着在你的双卷曲表达式周围加上引号,比如"{{ ... }}"
  • 您好@jediinspace,如果whites11的解决方案不起作用,您可以通过添加文件values.yaml来编辑问题吗?
  • 也尝试使用helm template --debug 打印出渲染的YAML;如果问题实际上是 image: 行,您可以看到它试图提交的内容。

标签: kubernetes kubernetes-helm


【解决方案1】:

所以我的解决方案是:

- image: '{{.Values.dockerRegistry}}/{{.Values.dockerImage}}:{{.Values.version}}'

问题在于printf函数和里面的冒号

"%s/%s:%s"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 2021-06-04
    • 2020-04-21
    • 2023-03-16
    • 2020-12-01
    • 2016-12-19
    相关资源
    最近更新 更多