gpt4 book ai didi

kubernetes - 出现错误 PodSpec.containers : got "map", Expected "array"或 Container.volumeMounts : got "map", Expected "array";

转载 作者:行者123 更新时间:2023-12-03 08:28:34 28 4
gpt4 key购买 nike

我正在尝试开始部署,但收到此错误

error: error validating "httpd-basic-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.containers): invalid type for io.k8s.api.core.v1.PodSpec.containers: got "map", expected "array"; if you choose to ignore these errors, turn validation off with --validate=false

以下 pod 定义文件:

apiVersion: apps/v1
kind: Deployment
metadata:
name: ebay-app
spec:
selector:
matchLabels:
environment: dev
app: ebay
replicas: 1
template:
metadata:
labels:
environment: dev
app: ebay
spec:

volumes:
- name: volume
hostPath:
path: /mnt/data

containers:
name: container1-nginx
image: nginx
volumeMounts:
name: volume
mountPath: /var/nginx-data

name: container2-tomcat
image: tomcat
nodeSelector:
boardType: x86vm

我尝试再次列出 cotnainers:

 volumes:
- name: volume
hostPath:
path: /mnt/data

containers:
- name: container1-nginx
image: nginx
volumeMounts:
name: volume
mountPath: /var/nginx-data

- name: container2-tomcat
image: tomcat

nodeSelector:
boardType: x86vm

这会导致不同的错误

error: error validating "httpd-basic-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.containers[0].volumeMounts): invalid type for io.k8s.api.core.v1.Container.volumeMounts: got "map", expected "array"; if you choose to ignore these errors, turn validation off with --validate=false

我做错了什么?

最佳答案

VolumeMounts 还应该有 -。它表示数组的开始。如下所示进行更改。

volumeMounts:
- name: volume
mountPath: /var/nginx-data

看看this example yaml创建具有两个容器并共享相同卷的 pod。在这个例子中,很清楚哪里使用 - 符号,哪里不使用。

关于kubernetes - 出现错误 PodSpec.containers : got "map", Expected "array"或 Container.volumeMounts : got "map", Expected "array";,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65854253/

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