Cloud Build-无法识别“推出重启”(未知命令)

时间:2019-11-07 10:32:57

标签: kubernetes google-kubernetes-engine google-cloud-build

我有一个小的cloudbuild.yaml文件,在其中构建Docker映像,将其推送到Google container registry(GCR),然后将所做的更改应用于我的Kubernetes集群。看起来像这样:

steps:

  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: [
    '-c',
    'docker pull gcr.io/$PROJECT_ID/frontend:latest || exit 0'
    ]

  - name: "gcr.io/cloud-builders/docker"
    args:
      [
        "build",
        "-f",
        "./services/frontend/prod.Dockerfile",
        "-t",
        "gcr.io/$PROJECT_ID/frontend:$REVISION_ID",
        "-t",
        "gcr.io/$PROJECT_ID/frontend:latest",
        ".",
      ]

  - name: "gcr.io/cloud-builders/docker"
    args: ["push", "gcr.io/$PROJECT_ID/frontend"]

  - name: "gcr.io/cloud-builders/kubectl"
    args: ["apply", "-f", "kubernetes/gcp/frontend.yaml"]
    env:
      - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
      - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"

  - name: "gcr.io/cloud-builders/kubectl"
    args: ["rollout", "restart", "deployment/frontend-deployment"]
    env:
      - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
      - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"

构建顺利进行,直到最后一步。 args: ["rollout", "restart", "deployment/frontend-deployment"]。它具有以下日志输出:

Already have image (with digest): gcr.io/cloud-builders/kubectl
Running: gcloud container clusters get-credentials --project="cents-ideas" --zone="europe-west3-a" "cents-ideas"
Fetching cluster endpoint and auth data.
kubeconfig entry generated for cents-ideas.
Running: kubectl rollout restart deployment/frontend-deployment
error: unknown command "restart deployment/frontend-deployment"
See 'kubectl rollout -h' for help and examples.

据称restart是未知命令。但是当我手动运行kubectl rollout restart deployment/frontend-deployment时,它可以工作。

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

看看Kubernetes release notesStream_Access命令是在v1.15版本中引入的。在您的情况下,似乎Cloud Build使用的是尚未执行此命令的旧版本。

进行一些测试后,Cloud Build似乎使用kubectl客户端版本,具体取决于集群的服务器版本。例如,运行以下版本时:

access File_Type

如果集群的主版本为v1.14,则Cloud Build使用v1.14 kubectl客户端并返回相同的kubectl rollout restart错误消息。当主版本为v1.15时,Cloud Build使用v1.15 kubectl客户端,该命令将成功运行。

关于您的情况,我怀疑您的群集“ cents-ideas”主版本为<1.15,这可以解释您遇到的错误。按照为什么当您手动运行命令时它起作用(我在本地理解),我怀疑您的kubectl可能已通过主版本> = 1.15的另一个集群进行了身份验证。