Da2ny
Da2ny

Reputation: 1027

kubernetes Unknown field "name" in io.k8s.api.core.v1.EnvFromSource

Here my command line:

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

and i got and error as this picture : enter image description here

Here my yaml file deployment:

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

And i got an error : Unknown field "name" in io.k8s.api.core.v1.EnvFromSource I have checked this error everyobdy says that is from space from envFrom however it is rightly indent as the solution they propose.

Upvotes: 13

Views: 17711

Answers (1)

Mike Bryant
Mike Bryant

Reputation: 1112

The indentation is wrong.

It should be:

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

i.e. name should be indented under the secretRef or configMapRef fields

Upvotes: 36

Related Questions