在运行bazel run //:kubernetes.apply的本地计算机上工作正常,但是尽管Google Cloud Build成功,但会记录这些错误.因此,该配置不适用于我的Kubernetes集群:Target //:kubernetes.apply up-to-date: bazel-bin/kubernetes.applyINFO: Elapsed time: 29.863s, Critical Path: 0.14sINFO: 0 processes.INFO: Build completed successfully, 1 total actionINFO: Running command line: bazel-bin/kubernetes.applyINFO: Build Event Protocol files produced successfully.INFO: Build completed successfully, 1 total actionkubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so projection_database_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so projection_database_k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_service.apply cannot be executed.我也从bazel缓存中得到了警告:DEBUG: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_k8s/toolchains/kubectl/kubectl_toolchain.bzl:28:9: No kubectl tool was found or built, executing run for rules_k8s targets might not work. P.S .:使用//:kubernetes.create 时遇到相同的错误我的设置 部署 load("@io_bazel_rules_k8s//k8s:object.bzl", "k8s_object")k8s_object( name = "k8s_deployment", kind = "deployment", cluster = "gke_cents-ideas_europe-west3-a_cents-ideas", template = ":ideas.deployment.yaml", images = { "gcr.io/cents-ideas/ideas:latest": ":image" },) 服务 k8s_object( name = "k8s_service", kind = "service", cluster = "gke_cents-ideas_europe-west3-a_cents-ideas", template = ":ideas.service.yaml",) 汇总 load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")k8s_objects( name = "k8s", objects = [ ":k8s_deployment", ":k8s_service", ]) 最终组成 k8s_objects( name = "kubernetes", objects = [ "//services/ideas:k8s", # ... ])更新我现在尝试使用Bazel和kubectl制作自己的docker映像:FROM gcr.io/cloud-builders/bazelRUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectlRUN chmod +x ./kubectlRUN mv ./kubectl /usr/local/bin/kubectl我将其推送到GCR并将cloudbuild.yaml更改为:steps: - name: eu.gcr.io/cents-ideas/bazel-kubectl args: ["run", "//:kubernetes.apply"]我首先注意到,这一步骤比以前花费了更长的时间.但是最后它会引发错误:$ /usr/local/bin/kubectl --kubeconfig= --cluster=gke_cents-ideas_europe-west3-a_cents-ideas --context= --user= apply -f -error: cluster "gke_cents-ideas_europe-west3-a_cents-ideas" does not exist 解决方案对于更新后的问题,现在您需要以某种方式对容器内的GKE进行身份验证.首先,我建议将gcloud工具安装到您的容器中.顺便说一句,至于1.2 GB的巨大容器大小,是因为cloud-builders/bazel很大:)看看我们的超薄bazel容器版本示例: https://github.com/aspect- development/bazel-k8s-example/blob/master/tools/Dockerfile.dazel这是用于安装gcloud和kubectl的Dockerfile,因此您可以从这两个文件中获取所需的部分: https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gcloud/Dockerfile第二件事是进行身份验证,在安装gcloud之后,它应该很容易.整个cloudbuild步骤应类似于以下内容:- name: <link to your container> entrypoint: /bin/sh args: - -c - | gcloud container clusters get-credentials cents-ideas --zone europe-west3-a --project cents-ideas bazel run //:kubernetes.applyI am trying to use rules_k8s for Bazel to deploy to my Kubernetes cluster.Thus I have this cloudbuild.yaml file, which is executed by Google Cloud Build:steps: - name: gcr.io/cloud-builders/bazel args: ['run', '//:kubernetes.apply'](//:kubernetes is just a k8s_objects)On my local machine running bazel run //:kubernetes.apply works fine, butalthough the Google Cloud Build succeeds, it logs those errors. So the configuration is not applied to my Kubernetes cluster:Target //:kubernetes.apply up-to-date: bazel-bin/kubernetes.applyINFO: Elapsed time: 29.863s, Critical Path: 0.14sINFO: 0 processes.INFO: Build completed successfully, 1 total actionINFO: Running command line: bazel-bin/kubernetes.applyINFO: Build Event Protocol files produced successfully.INFO: Build completed successfully, 1 total actionkubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so projection_database_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so projection_database_k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so k8s_service.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_deployment.apply cannot be executed.kubectl toolchain was not properly configured so event_store_k8s_service.apply cannot be executed.I also get a warning from the bazel cache:DEBUG: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_k8s/toolchains/kubectl/kubectl_toolchain.bzl:28:9: No kubectl tool was found or built, executing run for rules_k8s targets might not work.P.S.: I get the same errors when using //:kubernetes.createMy setupDeploymentsload("@io_bazel_rules_k8s//k8s:object.bzl", "k8s_object")k8s_object( name = "k8s_deployment", kind = "deployment", cluster = "gke_cents-ideas_europe-west3-a_cents-ideas", template = ":ideas.deployment.yaml", images = { "gcr.io/cents-ideas/ideas:latest": ":image" },)Servicesk8s_object( name = "k8s_service", kind = "service", cluster = "gke_cents-ideas_europe-west3-a_cents-ideas", template = ":ideas.service.yaml",)Aggregationsload("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")k8s_objects( name = "k8s", objects = [ ":k8s_deployment", ":k8s_service", ])Final compositionk8s_objects( name = "kubernetes", objects = [ "//services/ideas:k8s", # ... ])UpdateI've now tried to make my own docker image with Bazel and kubectl:FROM gcr.io/cloud-builders/bazelRUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectlRUN chmod +x ./kubectlRUN mv ./kubectl /usr/local/bin/kubectlI pushed it to GCR and changed my cloudbuild.yaml to:steps: - name: eu.gcr.io/cents-ideas/bazel-kubectl args: ["run", "//:kubernetes.apply"]I firstly noticed, that the step took way longer than before. However at the end it throws an error:$ /usr/local/bin/kubectl --kubeconfig= --cluster=gke_cents-ideas_europe-west3-a_cents-ideas --context= --user= apply -f -error: cluster "gke_cents-ideas_europe-west3-a_cents-ideas" does not existHere is the full log. 解决方案 As for the updated question, now you need to authenticate somehow to GKE inside the container.First thing, I recommend installing gcloud tool to your container.Btw, as for the huge container size 1.2 GB, that's because cloud-builders/bazel is huge :)Have a look at our example on slim bazel container version:https://github.com/aspect-development/bazel-k8s-example/blob/master/tools/Dockerfile.dazelAnd here is Dockerfile for installing gcloud and kubectl, so you can grab needed parts from both files:https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gcloud/DockerfileThe second thing is authenticating, after gcloud is installed it should be easy.Overall cloudbuild step should look similar to this:- name: <link to your container> entrypoint: /bin/sh args: - -c - | gcloud container clusters get-credentials cents-ideas --zone europe-west3-a --project cents-ideas bazel run //:kubernetes.apply 这篇关于Cloud Build Bazel错误:"kubectl工具链配置不正确,因此无法执行应用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-01 21:05