Bzlmod extensions for Kubernetes tooling

Module Extensions

k8s

k8s = use_extension("@rules_helm//k8s:extensions.bzl", "k8s")
k8s.kubectl(name, version)

Module extension for fetching Kubernetes tooling such as kubectl.

TAG CLASSES

kubectl

Fetch a kubectl binary for the host platform and register toolchains for it.

Each tag creates a host alias repository (default @kubectl) that exposes the binary as @{name}//:kubectl, which is the quickest way to inspect a cluster after a helm_install / helm_upgrade:

k8s = use_extension("@rules_helm//k8s:extensions.bzl", "k8s")
k8s.kubectl()
use_repo(k8s, "kubectl", "kubectl_toolchains")
register_toolchains("@kubectl_toolchains//:all")
bazel run @kubectl//:kubectl -- get pods --namespace my-release
bazel run @kubectl//:kubectl -- describe deployment my-release
bazel run @kubectl//:kubectl -- logs deployment/my-release --tail 100

The toolchains in @kubectl_toolchains serve the version requested by the root module's first kubectl tag (or the default when the root module has none).

Versions

rules_helm ships checksums for a single default version. Requesting any other version makes the extension download the upstream .sha256 files for that release while it is evaluated. On Bazel 8.5 and newer the digests are then stored as facts in MODULE.bazel.lock, so the lookup only happens once per version and airgapped builds work from the lockfile. Older Bazel versions repeat the lookup whenever the extension is re-evaluated.

k8s.kubectl(version = "1.36.5")

Attributes

NameDescriptionTypeMandatoryDefault
nameThe name of the host alias repository.Nameoptional"kubectl"
versionThe version of kubectl to fetch, without a leading v.Stringoptional"1.37.1"