2017-06-02 17 views
0

我是YAML格式和kubernetes的新手。映射值不允許在此上下文中

以下是dep_prom.yml文件。

--- 
apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    labels: 
    name: prometheus-deployment 
    name: prometheus 
    #namespace: prometheus 
spec: 
    replicas: 1 
    template: 
    metadata: 
     labels: 
     app: prometheus 
    spec: 
     containers: 
     - image: prom/prometheus:master 
     name: prometheus 
     command: 
     - "/bin/prometheus" 
     args: 
     - "-config.file=/etc/prometheus/prometheus.yml" 
     - "-storage.local.path=/prometheus" 
     - "-storage.local.retention=24h" 
     ports: 
     - containerPort: 9090 
      protocol: TCP 
     volumeMounts: 
     - mountPath: "/prometheus" 
      name: data 
     - mountPath: "/etc/prometheus" 
      name: config-volume 
     resources: 
      requests: 
      cpu: 100m 
      memory: 100Mi 
      limits: 
      cpu: 500m 
      memory: 2500Mi 
     volumes: 
     - name: data 
     hostPath: 
      path: /data/prometheus 
     - name: config-volume 
     configMap: 
      name: prometheus 
     nodeSelector: westporch-kubeminion-1 
     kubernetes.io/hostname: 10.0.24.52 
--- 

然而...當我執行kubectl創建-f dep_prom.yml

錯誤:誤差變換YAML到JSON:YAML:線47:映射值不允許在此上下文中

47號線是nodeSelector:westporch-kubeminion-1

我認爲YAML文件格式爲n ormal。

給我一些建議。

謝謝。

+1

刪除'westporch-kubeminion-1'。 'nodeSelector'是一個映射,而不是一個單獨的值字段。 – fishi

+0

[Kubectl總是返回一個錯誤:yaml:在此上下文中不允許映射值]的可能重複(https://stackoverflow.com/questions/40435173/kubectl-always-returns-a-error-yaml-mapping-values -are-不被允許功能於這個-CON) – Anthon

回答

0

如前所述,nodeSelector不能有這樣的值。它是指定鍵值對的映射。您可以閱讀更多關於具體使用here的信息。例如,nodeSelector的正確用法可能是:

nodeSelector: 
     disktype: ssd 
1

默認情況下,「kubernetes.io/hostname」是well known label包含節點的名稱,而不是它的IP地址。這可以通過運行$ kubectl get nodes --show-labels來檢查。因此,我建議做出以下更改:

nodeSelector: 
    kubernetes.io/hostname: westporch-kubeminion-1 
相關問題