简体   繁体   English

谷歌云 Kubernetes 部署错误:字段不可变

[英]Google cloud Kubernetes deployment error: Field is immutable

After fixing the problem from this topic Can't use Google Cloud Kubernetes substitutions (yaml files are all there, to not copy-paste them once again) I got a new problem.在解决了这个主题的问题后, 不能使用谷歌云 Kubernetes 替换(yaml 文件都在那里,不要再次复制粘贴它们)我遇到了一个新问题。 Making a new topic because there is the correct answer for the previous one.制作一个新主题,因为前一个主题有正确答案。

Step #2: Running: kubectl apply -f deployment.yaml步骤#2:运行:kubectl apply -f deployment.yaml
Step #2: Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply步骤 #2:警告:kubectl apply 应该用于由 kubectl create --save-config 或 kubectl apply 创建的资源
Step #2: The Deployment "myproject" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"myproject", "run":"myproject"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable步骤#2:部署“myproject”无效:spec.selector:无效值:v1.LabelSelector{MatchLabels:map[string]string{"app":"myproject", "run":"myproject"}, MatchExpressions: []v1.LabelSelectorRequirement(nil)}:字段不可变

I've checked similar issues but hasn't been able to find anything related.我检查了类似的问题,但找不到任何相关的东西。

Also, is that possible that this error related to upgrading App Engine -> Docker -> Kubernetes?另外,这个错误是否可能与升级 App Engine -> Docker -> Kubernetes 有关? I created valid configuration on each step.我在每一步都创建了有效的配置。 Maybe there are some things that were created and immutable now?也许现在有些东西是被创造出来的并且是不可变的? What should I do in this case?在这种情况下我该怎么办?

One more note, maybe that matters, it says "kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply" (you can see above), but executing还有一点,也许这很重要,它说“kubectl apply 应该用于由 kubectl create --save-config 或 kubectl apply 创建的资源”(你可以在上面看到),但是执行

kubectl create deployment myproject --image=gcr.io/myproject/myproject

gives me this给我这个

Error from server (AlreadyExists): deployments.apps "myproject" already exists来自服务器的错误(AlreadyExists):deployments.apps“myproject”已经存在

which is actually expected, but, at the same time, controversial with warning above (at least from my prospective)这实际上是预期的,但同时与上述警告有争议(至少从我的角度来看)

Any idea?任何想法?

Output of kubectl version kubectl kubectl version的Output

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.7", GitCommit:"8fca2ec50a6133511b771a11559e24191b1aa2b4", GitTreeState:"clean", BuildDate:"2019-09-18T14:47:22Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.11-gke.14", GitCommit:"56d89863d1033f9668ddd6e1c1aea81cd846ef88", GitTreeState:"clean", BuildDate:"2019-11-07T19:12:22Z", GoVersion:"go1.12.11b4", Compiler:"gc", Platform:"linux/amd64"}



Current YAML file:当前 YAML 文件:

steps:
  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: [
      '-c',
      'docker pull gcr.io/$PROJECT_ID/myproject:latest || exit 0'
    ]
  - name: 'gcr.io/cloud-builders/docker'
    args: [
      'build',
      '-t',
      'gcr.io/$PROJECT_ID/myproject:$BRANCH_NAME-$COMMIT_SHA',
      '-t',
      'gcr.io/$PROJECT_ID/myproject:latest',
      '.'
    ]
  - name: 'gcr.io/cloud-builders/kubectl'
    args: [ 'apply', '-f', 'deployment.yaml' ]
    env:
      - 'CLOUDSDK_COMPUTE_ZONE=<region>'
      - 'CLOUDSDK_CONTAINER_CLUSTER=myproject'
  - name: 'gcr.io/cloud-builders/kubectl'
    args: [
      'set',
      'image',
      'deployment',
      'myproject',
      'myproject=gcr.io/$PROJECT_ID/myproject:$BRANCH_NAME-$COMMIT_SHA'
    ]
    env:
      - 'CLOUDSDK_COMPUTE_ZONE=<region>'
      - 'CLOUDSDK_CONTAINER_CLUSTER=myproject'
      - 'DB_PORT=5432'
      - 'DB_SCHEMA=public'
      - 'TYPEORM_CONNECTION=postgres'
      - 'FE=myproject'
      - 'V=1'
      - 'CLEAR_DB=true'
      - 'BUCKET_NAME=myproject'
      - 'BUCKET_TYPE=google'
      - 'KMS_KEY_NAME=storagekey'
timeout: 1600s
images:
  - 'gcr.io/$PROJECT_ID/myproject:$BRANCH_NAME-$COMMIT_SHA'
  - 'gcr.io/$PROJECT_ID/myproject:latest

deployment.yaml部署.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myproject
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myproject
  template:
    metadata:
      labels:
        app: myproject
    spec:
      containers:
        - name: myproject
          image: gcr.io/myproject/github.com/weekendman/{{repo name here}}:latest
          ports:
            - containerPort: 80

From apps/v1 on, a Deployment's label selector is immutable after it gets created.从 apps/v1 开始,Deployment 的 label 选择器在创建后是不可变的。

excerpt from Kubernetes's document :摘自 Kubernetes 的文档

Note: In API version apps/v1, a Deployment's label selector is immutable after it gets created.注意:在 API 版本 apps/v1 中,Deployment 的 label 选择器在创建后是不可变的。

So, you can delete this deployment first, then apply it.因此,您可以先删除此部署,然后再应用它。

The MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable because it is different from your previous deployment. MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable ,因为它与您之前的部署不同。

Try looking at the existing deployment with kubectl get deployment -o yaml .尝试使用kubectl get deployment -o yaml查看现有部署。 I suspect the existing yaml has a different matchLables stanza.我怀疑现有的 yaml 有不同的matchLables节。

Specifically your file has:具体来说,您的文件具有:

    matchLabels:
      app: myproject

my guess is the output of kubectl get deployment -o yaml while have something different, like:我的猜测是kubectl get deployment -o yaml的 output 虽然有一些不同,比如:

    matchLabels:
      app: old-project-name

or或者

    matchLabels:
      app: myproject
      version: alpha

The new deployment cannot change the matchLabels stanza because, well, because it is immutable.新部署无法更改matchLabels节,因为它是不可变的。 That stanza in the new deployment must match the old.新部署中的该节必须与旧部署相匹配。 If you want to change it, you need to delete the old deployment with kubectl delete deployment myproject .如果要更改它,则需要使用kubectl delete deployment myproject删除旧部署。

Note: if you do that in production your app will be unavailable for a while.注意:如果您在生产环境中这样做,您的应用程序将有一段时间不可用。 (A much longer discussion about how to do this in production is not useful here.) (关于如何在生产中执行此操作的更长时间的讨论在这里没有用处。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Kubernetes Persistent Volume Claim 部署中的错误 Yaml - Google Cloud Kubernetes Persistent Volume Claim error in deployment Yaml Kube.netes 未加载 mongo 部署。 “无效值...字段是不可变的” - Kubernetes not loading mongo deployment. "Invalid value ... field is immutable" Apache 点燃谷歌云 Kubernetes 部署 - Apache Ignite Google cloud Kubernetes deployment 无法在谷歌云中使用kubernetes公开部署 - Not able to expose deployment using kubernetes in google cloud 通过 google-kubernetes-engine 部署:内部服务器错误 [500] (Google Cloud Platform) - Deployment via google-kubernetes-engine: Internal Server Error[500] (Google Cloud Platform) Google Cloud部署和Kubernetes节点IP地址更改 - Google Cloud deployment and Kubernetes node IP address change 使用Storage API从Kubernetes部署进行Google Cloud Bucket连接 - Google Cloud Bucket connection from Kubernetes deployment using Storage API Google Cloud Kubernetes Engine 中的 MongoDB 超时错误 - MongoDB timeout error in Google Cloud Kubernetes Engine IBM Cloud Kubernetes 部署的 URL - URL for IBM Cloud Kubernetes deployment 验证 Kubernetes 中的部署错误 - Validating Error on deployment in Kubernetes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM