Kubernetes 未加载 mongo 部署。 "Invalid value ... field is immutable"

Kubernetes not loading mongo deployment. "Invalid value ... field is immutable"

我的微服务项目 运行 skaffold dev 时出现以下错误。我直接从微服务教程中提取了代码,但仍然出现错误:

The Deployment "orders-mongo-depl" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"orders-mongo"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable
kubectl apply: exit status 1

这是我的“订单-mongo-depl.yaml”文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders-mongo-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orders-mongo
  template:
    metadata:
      labels:
        app: orders-mongo
    spec:
      containers:
        - name: orders-mongo
          image: mongo
---
apiVersion: v1
kind: Service
metadata:
  name: orders-mongo-srv
spec:
  selector:
    app: orders-mongo
  ports:
    - name: db
      protocol: TCP
      port: 27017
      targetPort: 27017

这是我的 skaffold.yaml 文件

apiVersion: skaffold/v2alpha3
kind: Config
deploy:
  kubectl:
    manifests:
      - ./infra/k8s/*
build:
  local:
    push: false
  artifacts:
    - image: stephengrider/auth
      context: auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: stephengrider/client
      context: client
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: '**/*.js'
            dest: .
    - image: stephengrider/tickets
      context: tickets
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: stephengrider/orders
      context: orders
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .

我试过重新启动 skaffold,删除并重新启动 Minikube,在 virtualbox 和 docker 之间更改 minikube 驱动程序,并重新启动我的计算机。我使用的是最新版本的 ubuntu 并且拥有最新的 minikube、kubernetes 和 docker.

因为它解决了问题,所以将其作为评论中的答案发布。

简答

要清理所有部署和对象,应发出以下命令:

skaffold delete

更多细节

在开发和测试期间创建对象。当在配置或对象本身中进行任何更改时,将触发错误,例如

The Deployment "orders-mongo-depl" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"orders-mongo"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

在 kubernetes 中的简短测试表明,在服务或开发中更改 selector 会产生完全相同的错误,这导致需要更正 manifest/objects 或在 skaffold 中重置部署(如果不清楚在哪里)差异来自.

Skaffold cleanup reference