kubernetes io.k8s.api.core.v1.EnvFromSource 中的未知字段“名称”

Da2*_*2ny 5 kubernetes

这是我的命令行:

kubectl apply -f postgres.secret.yaml \
-f postgres.configmap.yaml \
-f postgres.volume.yaml \
-f postgres.deployment.yaml \
-f postgres.service.yaml
Run Code Online (Sandbox Code Playgroud)

我得到了这张图片的错误: 在此处输入图片说明

这是我的 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
Run Code Online (Sandbox Code Playgroud)

我得到了一个错误: io.k8s.api.core.v1.EnvFromSource 中的未知字段“名称”

Mik*_*ant 13

缩进是错误的。

它应该是:

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

Run Code Online (Sandbox Code Playgroud)

name应在secretRefconfigMapRef字段下缩进