gpt4 book ai didi

Kubernetes未知字段 "volumes"

转载 作者:行者123 更新时间:2023-12-03 01:59:44 26 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

我相信你的缩进是错误的。 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从文档中查看它是如何完成的。

关于Kubernetes未知字段 "volumes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47923514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com