Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes unknown field "volumes"

Tags:

I am trying to deploy a simple nginx in kubernetes using hostvolumes. I use the next yaml:

apiVersion: extensions/v1beta1 kind: Deployment metadata:   name: webserver spec:   replicas: 1   template:     metadata:       labels:         app: webserver     spec:       containers:       - name: webserver         image: nginx:alpine         ports:         - containerPort: 80         volumeMounts:         - name: hostvol           mountPath: /usr/share/nginx/html     volumes:     - name: hostvol       hostPath:         path: /home/docker/vol 

When I deploy it kubectl create -f webserver.yaml, it throws the next error:

error: error validating "webserver.yaml": error validating data: ValidationError(Deployment.spec.template): unknown field "volumes" in io.k8s.api.core.v1.PodTemplateSpec; if you choose to ignore these errors, turn validation off with --validate=false 
like image 522
Asier Gomez Avatar asked Dec 21 '17 11:12

Asier Gomez


1 Answers

I believe you have the wrong indentation. The volumes key should be at the same level as containers.

apiVersion: extensions/v1beta1 kind: Deployment metadata:   name: webserver spec:   replicas: 1   template:     metadata:       labels:         app: webserver     spec:       containers:       - name: webserver         image: nginx:alpine         ports:         - containerPort: 80         volumeMounts:         - name: hostvol           mountPath: /usr/share/nginx/html       volumes:       - name: hostvol         hostPath:           path: /home/docker/vol 

Look at this wordpress example from the documentation to see how it's done.

like image 98
Jose Armesto Avatar answered Sep 27 '22 21:09

Jose Armesto