Kubernetes 使用podAffinity和podAntiaffinity时验证matchExpression时出错

Kubernetes 使用podAffinity和podAntiaffinity时验证matchExpression时出错,kubernetes,yaml,Kubernetes,Yaml,我正在尝试为部署在GCP集群内不同节点上的部署副本创建一个podAffinity,我遵循了此站点的文档,但在执行apply时出现了以下错误: error: error validating ".\\K8s\\6flask-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.affinity.podAntiAffinity.requiredDuringSch

我正在尝试为部署在GCP集群内不同节点上的部署副本创建一个podAffinity,我遵循了此站点的文档,但在执行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上的其他示例进行比较,我找不到错误

匹配表达式中指定的任何键值
也需要在pod
规范的
标签
匹配标签
中,而不是
元数据
第节。应如下所示

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"

那么matchExpressions是否需要同时出现在labels和matchLabels字段中呢?即使这样做,我仍然会遇到一个错误,正如您所说,我已经在上面用当前配置和输出错误更新了它使用
matchExpressions
而不是
matchExpressions
天哪,谢谢!