How to configure Okteto with Bazel

There is an open issue to add a Bazel sample since 2020 and not much else in the docs regarding Bazel.

I’ve configured a Bazel k8s_object rule that deploys a Helm chart and Go image to a local cluster but not sure how to adapt it to Okteto which seems to rely on having a Dockerfile present (instead of Bazel generating it).

Hey @bursty-john , welcome to the community!

Okteto uses a file called okteto.yaml in the root of the repo to tell Okteto how to build an deploy your development environment. You should be able to run the required bazel commands from there, a long as they are namespace-scoped:

# okteto.yaml
- name: Bazel

What are you trying to accomplish with Bazel?

Hey Ramiro,

We’re trying to migrate to Bazel for a variety of reasons including faster build times. The command is:

bazel run :k8s_okteto.apply

but when it runs directly or via Okteto it gives an auth error:

Unable to publish images: unable to push image GET
unexpected status code 401 Unauthorized

The bazel rule looks like:

  name = "k8s_okteto",
  kind = "deployment",
  cluster = "mycluser",
  namespace = "mynamespace",
  template = ":helm_okteto",
    images = {
     "" + service: ":go_image",

What is bazel using underneath to build the container image? Based on the error, it seems like you need need to authenticate with the Okteto registry before pushing the image.

If you are using the docker daemon to build the image, you can do it by running something like:


If you can put your bazel files on a public repo, I can help take a look (not an expert in Bazel though :P).

Thanks Ramiro, that helped me get past the auth error.

- name: Docker Login
- name: Deploy
  command: bazel run :k8s_okteto.apply

It might be possible to login using rules_k8s or rules_docker but that’s another problem.

1 Like

That would be very cool, I’m not an expert in Bazel but maybe someone in the community can contribute here? :smile: