Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kubernetes

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.

like image 522
Da2ny Avatar asked Nov 15 '20 16:11

Da2ny


1 Answers

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

like image 141
Mike Bryant Avatar answered Nov 10 '22 01:11

Mike Bryant