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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With