Kubernetes未知领域“卷”

时间:2017-12-21 11:01:12

标签: kubernetes

我正在尝试使用hostvolumes在kubernetes中部署一个简单的nginx。我使用下一个 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

当我部署它kubectl create -f webserver.yaml时,它会抛出下一个错误:

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

1 个答案:

答案 0 :(得分:14)

我相信你有错误的缩进。 volumes密钥应与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

从文档中查看this wordpress example,看看它是如何完成的。