Bazel k8s_deploy Does not Apply Kubernetes Resources to Cluster

2/2/2020

I have multiple Bazel rules for deploying Kubernetes

  1. deployments:
load("@k8s_deploy//:defaults.bzl", "k8s_deploy")
k8s_object(
  name = "k8s_deployment",
  kind = "deployment",
  cluster = "cents-ideas",
  template = ":ideas.deployment.yaml",
  images = {
    "gcr.io/cents-ideas/ideas:latest": ":image"
  },
)
  1. services:
k8s_object(
  name = "k8s_service",
  kind = "service",
  template = ":ideas.service.yaml",
)

And I've put all those k8s_object together into a single k8s_objects like this:

load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")
k8s_objects(
    name = "k8s",
    objects = [
      ":k8s_deployment",
      ":k8s_service"
    ]
)

Lastly, I have a cloudbuild.yaml file which runs the k8s_objects rule:

steps:
  - id: 'push docker images and deploy changes to kubernetes'
    name: gcr.io/cloud-builders/bazel
    args: ['run', '//:kubernetes']

But the Kubernetes resources are not applied to the cluster, although the Cloud Build succeeds: cloud build

Here is the full build log.

So basically the images are pushed to the container registry and then the modified .yaml files are logged, but not applied to my Google Kubernetes Engine cluster.

-- Florian Ludewig
bazel
google-cloud-build
google-kubernetes-engine
kubernetes

1 Answer

2/2/2020

I think you need to suffix the target with ".create" or ".replace" see docs

So you would want something like:

bazel run //:k8s.create

where k8s is your target name.

-- user2515975
Source: StackOverflow