【问题标题】:kubernetes Unknown field "name" in io.k8s.api.core.v1.EnvFromSourcekubernetes io.k8s.api.core.v1.EnvFromSource 中的未知字段“名称”
【发布时间】:2021-02-26 23:47:16
【问题描述】:

这里是我的命令行:

kubectl apply -f postgres.secret.yaml \
-f postgres.configmap.yaml \
-f postgres.volume.yaml \
-f postgres.deployment.yaml \
-f postgres.service.yaml

我得到了这张图片的错误:

这里是我的 yaml 文件部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 0
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      restartPolicy: Always
      containers:
        - name: postgres
          image: postgres:12
          ports:
            - containerPort: 5432
          envFrom:
            - secretRef:
              name: postgres-secret
            - configMapRef:
              name: postgres-configmap
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgres-pv
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pv-claim

我收到一个错误:io.k8s.api.core.v1.EnvFromSource 中的未知字段“名称” 我已经检查了这个错误,每个人都说这是来自 envFrom 的空间,但它与他们提出的解决方案一样缩进。

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    缩进错误。

    应该是:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: postgres
    spec:
      replicas: 0
      selector:
        matchLabels:
          app: postgres
      template:
        metadata:
          labels:
            app: postgres
        spec:
          restartPolicy: Always
          containers:
            - name: postgres
              image: postgres:12
              ports:
                - containerPort: 5432
              envFrom:
                - secretRef:
                    name: postgres-secret
                - configMapRef:
                    name: postgres-configmap
              volumeMounts:
                - mountPath: /var/lib/postgresql/data
                  name: postgres-pv
          volumes:
            - name: postgredb
              persistentVolumeClaim:
                claimName: postgres-pv-claim
    
    

    name 应在 secretRefconfigMapRef 字段下缩进

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      相关资源
      最近更新 更多