Building and testing Kubernetes with Bazel is supported but not yet default.
Instructions for installing Bazel can be found here.
make rules have been created for common operations:
make bazel-build: builds all binaries in tree
make bazel-test: runs all unit tests
make bazel-test-integration: runs all integration tests
make bazel-release: builds release tarballs, Docker images (for server components), and Debian images
You can also interact with Bazel directly; for example, to run all
$ bazel test //pkg/kubectl/...
If you don’t want to install Bazel, you can instead try using the unofficial Planter tool, which runs Bazel inside a Docker container.
For example, you can run
$ ../test-infra/planter/planter.sh make bazel-test $ ../test-infra/planter/planter.sh bazel build //cmd/kubectl
Similar jobs are run on all PRs; additionally, several of the e2e jobs use Bazel-built binaries when launching and testing Kubernetes clusters.
Cross-compilation is not currently supported, so all binaries will be built for the host OS and architecture running Bazel. (For example, you can’t currently target linux/amd64 from macOS or linux/s390x from an amd64 machine.)
Additionally, native macOS support is still a work in progress. Using Planter is a possible workaround in the interim.
Bazel does not validate build environment, thus make sure that needed
tools and development packages are installed in the system. Bazel builds require presence of
glibc and libstdc++ development headers and
glibc static development libraries. Please check your distribution for exact names of the packages. Examples for some commonly used distributions are below:
|GNU Libc static files||
BUILD files, run:
To prevent Go rules from being updated, consult the gazelle documentation.
Note that much like Go files and
gofmt, BUILD files have standardized,
opinionated style rules, and running
hack/update-bazel.sh will format them for you.
If you want to auto-format BUILD files in your editor, using something like Buildifier is recommended.
BUILD file for a package will be required when:
* Files are added to or removed from a package
* Import dependencies change for a package
BUILD file has been updated and needs to be reformatted
* A new
BUILD file has been added (parent
BUILD files will be updated)
For help or discussion, join the #bazel channel on Kubernetes Slack.