Kubernetes未知领域“卷”

问题描述 投票:8回答:1

我正在尝试使用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
kubernetes
1个回答
13
投票

我相信你有错误的缩进。 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,看看它是如何完成的。

© www.soinside.com 2019 - 2024. All rights reserved.