kubectl apply -f error invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchLabels: got "map", expected "string"

kubectl apply -f error invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchLabels: got "map", expected "string"

希望你一切顺利

拜托,我无法创建这个 Deployment

我不知道为什么或可能是什么错误。

似乎有些人已经遇到过这个错误,但我从评论中不明白他们是如何解决的。

我查看了 Kubernetes 文档,但没有找到。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: analysis-api
  labels:
    tier: msvc
    name: analysis-api
    component: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      labels:
        tier: msvc
        name: analysis-api
        component: backend
  template:
    metadata:
      labels:
        tier: msvc
        name: analysis-api
        component: backend
    spec:
      containers:
      - name: main
        image: guitou-app/msvc-analysis-api
        env:
        - name: ENV
          value: dev
        - name: MONGODB_URI
          valueFrom:
            configMapKeyRef:
              name: env-vars
              key: MONGODB_URI
        - name: MONGODB_DBNAME
          value: guitou-analysis

我遇到了这个错误

error: error validating "infra/k8s/analysis-api.yaml": error validating data: ValidationError(Deployment.spec.selector.matchLabels.labels): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchLabels: got "map", expected "string"; if you choose to ignore these errors, turn validation off with --validate=false

但我不知道这是什么意思。 metadata.labelsspec.template.labelsspec.selector.matchLabels 完全相同.

我应该从哪里开始寻找解决方案?

应该是这样的

selector:
    matchLabels:
      tier: msvc
      name: analysis-api
      component: backend

改为

selector:
    matchLabels:
      labels:
        tier: msvc
        name: analysis-api
        component: backend