【问题标题】:Yam file error e error converting YAML to JSON: yaml: line 8: mapping values are not allowed in this contextYam 文件错误 e 将 YAML 转换为 JSON 时出错:yaml: line 8: mapping values are not allowed in this context
【发布时间】:2021-08-10 00:44:37
【问题描述】:

这是我第一次尝试 Kubernetes。尝试安装 minios 存储我发现 yaml 文件中的错误

apiVersion: v1
kind: PersistentVolume
metadata:
   name: pv-name-1
spec:
   capacity:
      storage: 1Ti
   volumeMode: Filesystem
   accessModes:
   - ReadWriteOnce
   persistentVolumeReclaimPolicy: Retain
   storage-class: local-storage
   local:
      path: /mnt/d/minio
   nodeAffinity:
      required:
         nodeSelectorTerms:
         - matchExpressions:
            - key: kubernetes.io/hostname
               operator: In
               values:
               - docker-desktop

错误:解析 pvc-1.yaml 时出错:将 YAML 转换为 JSON 时出错:yaml:第 8 行:此上下文中不允许映射值

【问题讨论】:

    标签: kubernetes kubernetes-pod minio


    【解决方案1】:

    您在关联下的缩进不正确。一些专门用于 Kubernetes 的 yaml 文件的第 3 方 linter 超链接 here

    另外,storage-class 应该是 storageCalssName

    apiVersion: v1
    kind: PersistentVolume
    metadata:
       name: pv-name-1
    spec:
       capacity:
          storage: 1Ti
       volumeMode: Filesystem
       accessModes:
       - ReadWriteOnce
       persistentVolumeReclaimPolicy: Retain
       #storage-class: local-storage <--this should be StorageClassName
       local:
          path: /mnt/d/minio
       nodeAffinity:
          required:
             nodeSelectorTerms:
             - matchExpressions:
               - key: kubernetes.io/hostname In #<-----------this and below  lines are moved one place left
                 operator: 
                 values:
                 - docker-desktop
    

    【讨论】:

    • 我也使用了这个,它显示了同样的错误。错误在第 8 行是它抛出的内容。我使用了几个 yaml 在线验证器,语法看起来不错
    • 当你将文本从这里复制到终端时(假设 vim),在vim中使用:set paste
    • 另外,当您使用storage-class 时,您会尝试设置什么? dd 你的意思是storageClassName
    • cat pv.yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: local-storage provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer kubectl create -f pv.yaml kubectl get sc kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEPANSION AGE hostpath (default) docker.io/hostpath Delete Immediate false 131m local-storage kubernetes.io/no-provisioner Delete WaitForFirstConsumer
    • 我创建了另一个存储类,并为此使用了 local-storage 这个名称
    猜你喜欢
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2016-02-16
    • 2019-02-24
    • 1970-01-01
    • 2019-11-18
    相关资源
    最近更新 更多