我正在尝试为要部署在 GCP 集群内的不同节点中的部署副本创建 podAffinity,我已遵循此站点https://thenewstack.io/implement-node-and-pod-affinity-上的文档anti-affinity-in-kubernetes-a-practical-example/但在执行 apply 时出现此错误:
error: error validating ".\\K8s\\6flask-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution[0].labelSelector): unknown field "MatchExpressions" in io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector;
Run Code Online (Sandbox Code Playgroud)
这是我的flask-deployment.yaml。我尝试将其也设置在第一个规范下,但它也不起作用
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-deployment
namespace: flask-app
spec:
replicas: 2
selector:
matchLabels:
app: flask-app
deploy: separate
run: together
template:
metadata:
labels:
app: flask-app
deploy: separate
run: together
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
MatchExpressions:
- key: deploy
operator: In
values:
- separate
topologyKey: kubernetes.io/hostname
containers:
Run Code Online (Sandbox Code Playgroud)
难道是身份识别错误?kubernetes linter 没有标记任何内容,我一直在与 SO 和网络上的其他示例进行比较,但我找不到错误
您指定的任何键值matchExpressions也需要位于labelspodmatchLabels中spec而不是metadata部分中。它应该如下所示
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
namespace: flask-app
spec:
replicas: 2
selector:
matchLabels:
deploy: separate
template:
metadata:
labels:
deploy: separate
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: deploy
operator: In
values:
- separate
topologyKey: "kubernetes.io/hostname"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4003 次 |
| 最近记录: |