apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 5 template: metadata: labels: app: nginx spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringEXecution: nodeSelectorTerms: - matchExpressions: - key: gpu operator: In values: - "true" containers: - name: nginx image: registry.cn-hangzhou.aliyuncs.com/wsl_images/nginx:latest imagePullPolicy: IfNotPresent ports: - containerPort: 80 执行后报错[root@server1 ~]# kubectl apply -f nginx.yaml Error from server (BadRequest): error when creating "nginx.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringEXecution"
时间: 2024-02-10 14:27:17 浏览: 370
根据你提供的错误信息,这是由于 Deployment 中的 spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringEXecution 字段在 Kubernetes 版本中没有被识别导致的。这个字段在 Kubernetes 1.18 版本之后的版本才被引入。
你可以将该字段修改为 `requiredDuringSchedulingIgnoredDuringExecution` (注意拼写),然后再次尝试应用该部署文件。修改后的部署文件如下所示:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 5
template:
metadata:
labels:
app: nginx
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gpu
operator: In
values:
- "true"
containers:
- name: nginx
image: registry.cn-hangzhou.aliyuncs.com/wsl_images/nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
```
然后使用 `kubectl apply -f nginx.yaml` 命令再次尝试部署该文件。
阅读全文
相关推荐


















