使用podAffinity和podAntiaffinity时验证matchExpression错误



我正在尝试为我的部署的副本创建一个podAffinity,以便在我的GCP集群内的不同节点中部署,我遵循了这个网站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;

这是我的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:

是标识错误吗?kubernetes linter没有标记任何东西,我一直在与SO和web中的其他示例进行比较,我找不到错误

您在matchExpressions中指定的任何键值也需要在podspeclabelsmatchLabels中,而不是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"

相关内容

  • 没有找到相关文章

最新更新