【问题标题】:kubectl deployment failingkubectl 部署失败
【发布时间】:2019-04-22 08:34:24
【问题描述】:

我正在为 GKE 上的 Spring 启动应用程序设置 CI CD 管道。 CI 构建步骤工作正常,但交付构建步骤由于“错误:没有传递给应用的对象”错误而失败。我可以在云构建中看到以下日志

Starting Step #0 - "Deploy"
Step #0 - "Deploy": Already have image (with digest): gcr.io/cloud-builders/kubectl
Step #0 - "Deploy": Running: gcloud container clusters get-credentials --project="location-finder-kubernetes" --zone="us-central1-b" "location-finder"
Step #0 - "Deploy": Fetching cluster endpoint and auth data.
Step #0 - "Deploy": kubeconfig entry generated for location-finder.
Step #0 - "Deploy": Running: kubectl apply -f kubernetes.yaml
Step #0 - "Deploy": error: no objects passed to apply
Finished Step #0 - "Deploy"
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/kubectl" failed: exit status 1

其中 location-finder 是集群的名称。

为了设置这个管道,我遵循了https://cloud.google.com/kubernetes-engine/docs/tutorials/gitops-cloud-build 中提到的所有准则

此失败步骤的 cloudbuild.yaml 内容为

steps:
- name: 'gcr.io/cloud-builders/kubectl'
  id: Deploy
  args:
  - 'apply'
  - '-f'
  - 'kubernetes.yaml'
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=us-central1-b'
  - 'CLOUDSDK_CONTAINER_CLUSTER=location-finder'

Kubectl 版本:

kubectl version
Client Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.9-dispatcher", GitCommit:"e3f5193e8f1091a162af7e17a781e6a3129bcfd0", GitTreeState:"clean", BuildDate:"2019-03-28T18:13:46Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.8-gke.6", GitCommit:"394ee507d00f15a63cef577a14026096c310698e", GitTreeState:"clean", BuildDate:"2019-03-30T19:31:43Z", GoVersion:"go1.10.8b4", Compiler:"gc", Platform:"linux/amd64"}

我是否缺少任何配置?

【问题讨论】:

  • 嗨,Swapnil,你能发给你kubernetes.yaml 文件吗?
  • 按照文档中提到的步骤,有一个名为kubectl.yaml.tpl的模板文件。使用此文件,自动化过程会创建最终的 kubernetes.yaml 文件。忘记将该模板文件添加到源代码管理是我的错误。 @Arslanbekov,您要求提供相同的文件,这给了我一个提示来弄清楚。感谢回复!

标签: kubernetes kubectl


【解决方案1】:

为了测试,我运行了相同的 kubectl apply -f kubernetes.yaml,但传递了一个空的 yaml 文件并得到了和你一样的错误。您的 yaml 文件中是否有任何内容?

【讨论】:

  • 是的,这个文件不能为空。参考文档,按原样使用。只需将集群名称替换为您的集群名称即可。
  • 哈哈。我用“touch my.yaml”开始了这个文件。在 VSCode 中提出它,添加了一堆东西,但从未保存它!一个“duh”的时刻。
【解决方案2】:

kubernetes.yaml 文件中的对象很可能未正确定义。

请检查文件并确认您能够手动部署它。如果它有效,那么持续交付也应该有效。

【讨论】:

    【解决方案3】:

    我也面临同样的问题,请参阅 Google Docs for CI/CD on GKE。

    你有同样的解决方案吗?

    BUILD Starting Step #0 - "Deploy"
    Step #0 - "Deploy": Already have image (with digest): gcr.io/cloud-builders/kubectl
    Step #0 - "Deploy": Running: gcloud container clusters get-credentials --project="amcartecom" --zone="us-central1-b" "hello-cloudbuild"
    Step #0 - "Deploy": Fetching cluster endpoint and auth data.
    Step #0 - "Deploy": kubeconfig entry generated for hello-cloudbuild.
    Step #0 - "Deploy": Running: kubectl apply -f kubernetes.yaml
    Step #0 - "Deploy": error: no objects passed to apply
    Finished Step #0 - "Deploy"
    ERROR
    ERROR: build step 0 "gcr.io/cloud-builders/kubectl" failed: exit status 1
    

    【讨论】:

      【解决方案4】:

      请检查您是否在 yaml 文件中输入了命名空间。这对我有用。

      【讨论】:

      • 不要在答题部分...
      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 2021-04-23
      • 2020-01-06
      • 2013-04-08
      • 2012-10-29
      • 2016-10-24
      相关资源
      最近更新 更多