【问题标题】: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"
【发布时间】:2021-07-07 05:34:50
【问题描述】:

希望你过得好

请,我无法创建此部署

我不知道错误的原因或可能是什么。

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

我查看了 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 都是相同的。

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

【问题讨论】:

    标签: kubernetes yaml kubernetes-deployment


    【解决方案1】:

    应该是这样的

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

    改为

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

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 2022-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      相关资源
      最近更新 更多