Я пытаюсь использовать rules_k8s для развертывания Bazel в моем кластере Kubernetes.
Таким образом, у меня есть файл cloudbuild.yaml
, который выполняется Google Cloud Build:
steps:
- name: gcr.io/cloud-builders/bazel
args: ['run', '//:kubernetes.apply']
(//:kubernetes
- это всего лишь k8s_objects
)
На моей локальной машине работает bazel run //:kubernetes.apply
, но работает успешно, но Google Cloud Build работает успешно , он регистрирует эти ошибки. Таким образом, конфигурация не применяется к моему кластеру Kubernetes:
Target //:kubernetes.apply up-to-date:
bazel-bin/kubernetes.apply
INFO: Elapsed time: 29.863s, Critical Path: 0.14s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/kubernetes.apply
INFO: Build Event Protocol files produced successfully.
INFO: Build completed successfully, 1 total action
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 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.
PS: я получаю те же ошибки при использовании //: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",
# ...
]
)
Обновление
Я уже пытался создать собственное docker изображение с помощью Bazel и kubectl:
FROM gcr.io/cloud-builders/bazel
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN 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
Здесь - полный журнал.