首页 > 解决方案 > Bazel Kubernetes 对象错误:没有对象传递给应用(Google 容器注册表)

问题描述

我有一条k8s_object规则可以将部署应用到我的 Google Kubernetes 集群。这是我的设置:

load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
nodejs_image(
    name = "image",
    data = [":lib", "//:package.json"],
    entry_point = ":index.ts",
)

load("@io_bazel_rules_k8s//k8s:object.bzl", "k8s_object")
k8s_object(
  name = "k8s_deployment",
  template = ":gateway.deployment.yaml",
  kind = "deployment",
  cluster = "gke_cents-ideas_europe-west3-b_cents-ideas",
  images = {
    "gcr.io/cents-ideas/gateway:latest": ":image"
  },
)

但是当我运行时bazel run //services/gateway:k8s_deployment.apply,出现以下错误

INFO: Analyzed target //services/gateway:k8s_deployment.apply (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //services/gateway:k8s_deployment.apply up-to-date:
  bazel-bin/services/gateway/k8s_deployment.apply
INFO: Elapsed time: 0.113s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
$ /snap/bin/kubectl --kubeconfig= --cluster=gke_cents-ideas_europe-west3-b_cents-ideas --context= --user= apply -f -
2020/02/12 14:52:44 Unable to publish images: unable to publish image gcr.io/cents-ideas/gateway:latest
error: no objects passed to apply

错误:没有传递给应用的对象 它不会将新图像推送到谷歌容器注册表。

奇怪的是,这几天前奏效了。但我没有改变任何东西。

如果您需要仔细查看,这里是完整的代码:https ://github.com/flolude/cents-ideas/blob/069c773ade88dfa8aff492f024a1ade1f8ed282e/services/gateway/BUILD

更新

我不知道这是否与这个问题有关,但是当我运行时

gcloud auth configure-docker

我收到一些警告:

WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
WARNING: Your config file at [/home/flolu/.docker/config.json] contains these credential helper entries:

{
  "credHelpers": {
    "asia.gcr.io": "gcloud", 
    "staging-k8s.gcr.io": "gcloud", 
    "us.gcr.io": "gcloud", 
    "gcr.io": "gcloud", 
    "marketplace.gcr.io": "gcloud", 
    "eu.gcr.io": "gcloud"
  }
}
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
gcloud credential helpers already registered correctly.

标签: kubernetesgoogle-kubernetes-enginebazelkubectlgoogle-container-registry

解决方案


我已经google-cloud-sdk通过snap install. 我所做的就是通过google-cloud-sdk删除

snap remove google-cloud-sdk

然后按照这些说明通过以下方式安装它

sudo apt install google-cloud-sdk

现在它工作正常


推荐阅读