gpt4 book ai didi

kubectl ValidationError(Deployment.spec) : missing required field "selector" in io. k8s.api.apps.v1.DeploymentSpec;

转载 作者:行者123 更新时间:2023-12-05 00:57:26 24 4
gpt4 key购买 nike

当我尝试运行 kubectl apply -f 02-php-apache-deployment.yaml 我收到以下错误:

错误:验证“02-php-apache-deployment.yaml”时出错:验证数据时出错:ValidationError(Deployment.spec):io.k8s.api.apps.v1 中缺少必填字段“selector”。部署规范;如果您选择忽略这些错误,请使用 --validate=false

关闭验证

这是我的部署 yml 文件:

apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
spec:
replicas: 3
template:
metadata:
labels:
role: php-apache
spec:
containers:
- name: php-apache
image: k8s.gcr.io/hpa-example
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
env:
- name: MYSQL_ROOT_PASSWORD
value: "password"
resources:
requests:
memory: "64Mi"
cpu: "200m"
limits:
memory: "128Mi"
cpu: "500m"

我使用的是 minikube v1.6.2 版

和 kubectl 版本:

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.8", GitCommit:"211047e9a1922595eaa3a1127ed365e9299a6c23", GitTreeState:"clean", BuildDate:"2019-10-15T12:11:03Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:12:17Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}

最佳答案

好的,我发现我错过了其中的选择器 matchLabels 和应用程序。

我改变了这 block :

spec:
replicas: 3
selector:
matchLabels:
app: php-apache
template:
metadata:
labels:
app: php-apache

最终正确的 yml 文件:

apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
spec:
replicas: 3
selector:
matchLabels:
app: php-apache
template:
metadata:
labels:
app: php-apache
spec:
containers:
- name: php-apache
image: k8s.gcr.io/hpa-example
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
env:
- name: MYSQL_ROOT_PASSWORD
value: "password"
resources:
requests:
memory: "64Mi"
cpu: "200m"
limits:
memory: "128Mi"
cpu: "500m"

关于kubectl ValidationError(Deployment.spec) : missing required field "selector" in io. k8s.api.apps.v1.DeploymentSpec;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60126299/

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