• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..15-Sep-2021-

build-image/H15-Sep-2021-15598

lib/H15-Sep-2021-591371

pause/H15-Sep-2021-497320

root/H15-Sep-2021-1,210600

server-image/H15-Sep-2021-5445

OWNERSH A D15-Sep-2021442 2523

README.mdH A D15-Sep-20216.5 KiB8358

common.shH A D15-Sep-202125.4 KiB700437

copy-output.shH A D15-Sep-2021883 277

dependencies.yamlH A D15-Sep-20219.4 KiB237216

make-build-image.shH A D15-Sep-20211.1 KiB327

make-clean.shH A D15-Sep-2021845 277

nsswitch.confH A D15-Sep-202168 31

package-tarballs.shH A D15-Sep-2021914 289

release-images.shH A D15-Sep-20211.6 KiB4518

release-in-a-container.shH A D15-Sep-20211.3 KiB5022

release.shH A D15-Sep-20211.4 KiB4616

run.shH A D15-Sep-20211.4 KiB4417

shell.shH A D15-Sep-2021939 296

tools.goH A D15-Sep-20211.1 KiB3211

util.shH A D15-Sep-20211.3 KiB338

README.md

1# Building Kubernetes
2
3Building Kubernetes is easy if you take advantage of the containerized build environment. This document will help guide you through understanding this build process.
4
5## Requirements
6
71. Docker, using one of the following configurations:
8  * **macOS** Install Docker for Mac. See installation instructions [here](https://docs.docker.com/docker-for-mac/).
9     **Note**: You will want to set the Docker VM to have at least 8GB of initial memory or building will likely fail. (See: [#11852]( http://issue.k8s.io/11852)).
10  * **Linux with local Docker**  Install Docker according to the [instructions](https://docs.docker.com/installation/#installation) for your OS.
11  * **Windows with Docker Desktop WSL2 backend**  Install Docker according to the [instructions](https://docs.docker.com/docker-for-windows/wsl-tech-preview/). Be sure to store your sources in the local Linux file system, not the Windows remote mount at `/mnt/c`.
12  **Note**: You will need to check if Docker CLI plugin buildx is properly installed. You can install buildx according to the [instructions](https://github.com/docker/buildx/blob/master/README.md#installing).
132. **Optional** [Google Cloud SDK](https://developers.google.com/cloud/sdk/)
14
15You must install and configure Google Cloud SDK if you want to upload your release to Google Cloud Storage and may safely omit this otherwise.
16
17## Overview
18
19While it is possible to build Kubernetes using a local golang installation, we have a build process that runs in a Docker container.  This simplifies initial set up and provides for a very consistent build and test environment.
20
21## Key scripts
22
23The following scripts are found in the [`build/`](.) directory. Note that all scripts must be run from the Kubernetes root directory.
24
25* [`build/run.sh`](run.sh): Run a command in a build docker container.  Common invocations:
26  *  `build/run.sh make`: Build just linux binaries in the container.  Pass options and packages as necessary.
27  *  `build/run.sh make cross`: Build all binaries for all platforms. To build only a specific platform, add `KUBE_BUILD_PLATFORMS=<os>/<arch>`
28  *  `build/run.sh make kubectl KUBE_BUILD_PLATFORMS=darwin/amd64`: Build the specific binary for the specific platform (`kubectl` and `darwin/amd64` respectively in this example)
29  *  `build/run.sh make test`: Run all unit tests
30  *  `build/run.sh make test-integration`: Run integration test
31  *  `build/run.sh make test-cmd`: Run CLI tests
32* [`build/copy-output.sh`](copy-output.sh): This will copy the contents of `_output/dockerized/bin` from the Docker container to the local `_output/dockerized/bin`. It will also copy out specific file patterns that are generated as part of the build process. This is run automatically as part of `build/run.sh`.
33* [`build/make-clean.sh`](make-clean.sh): Clean out the contents of `_output`, remove any locally built container images and remove the data container.
34* [`build/shell.sh`](shell.sh): Drop into a `bash` shell in a build container with a snapshot of the current repo code.
35
36## Basic Flow
37
38The scripts directly under [`build/`](.) are used to build and test.  They will ensure that the `kube-build` Docker image is built (based on [`build/build-image/Dockerfile`](build-image/Dockerfile) and after base image's `KUBE_BUILD_IMAGE_CROSS_TAG` from Dockerfile is replaced with one of those actual tags of the base image, like `v1.13.9-2`) and then execute the appropriate command in that container.  These scripts will both ensure that the right data is cached from run to run for incremental builds and will copy the results back out of the container. You can specify a different registry/name for `kube-cross` by setting `KUBE_BASE_IMAGE_REGISTRY` which defaults to  `k8s.gcr.io/build-image`.
39
40The `kube-build` container image is built by first creating a "context" directory in `_output/images/build-image`.  It is done there instead of at the root of the Kubernetes repo to minimize the amount of data we need to package up when building the image.
41
42There are 3 different containers instances that are run from this image.  The first is a "data" container to store all data that needs to persist across to support incremental builds. Next there is an "rsync" container that is used to transfer data in and out to the data container.  Lastly there is a "build" container that is used for actually doing build actions.  The data container persists across runs while the rsync and build containers are deleted after each use.
43
44`rsync` is used transparently behind the scenes to efficiently move data in and out of the container.  This will use an ephemeral port picked by Docker.  You can modify this by setting the `KUBE_RSYNC_PORT` env variable.
45
46All Docker names are suffixed with a hash derived from the file path (to allow concurrent usage on things like CI machines) and a version number.  When the version number changes all state is cleared and clean build is started.  This allows the build infrastructure to be changed and signal to CI systems that old artifacts need to be deleted.
47
48## Releasing
49
50The [`build/release.sh`](release.sh) script will build a release.  It will build binaries, run tests, (optionally) build runtime Docker images.
51
52The main output is a tar file: `kubernetes.tar.gz`.  This includes:
53* Cross compiled client utilities.
54* Script (`kubectl`) for picking and running the right client binary based on platform.
55* Examples
56* Cluster deployment scripts for various clouds
57* Tar file containing all server binaries
58
59In addition, there are some other tar files that are created:
60* `kubernetes-client-*.tar.gz` Client binaries for a specific platform.
61* `kubernetes-server-*.tar.gz` Server binaries for a specific platform.
62
63When building final release tars, they are first staged into `_output/release-stage` before being tar'd up and put into `_output/release-tars`.
64
65## Reproducibility
66`make release` and its variant `make quick-release` provide a
67hermetic build environment which should provide some level of reproducibility
68for builds. `make` itself is **not** hermetic.
69
70The Kubernetes build environment supports the [`SOURCE_DATE_EPOCH` environment
71variable](https://reproducible-builds.org/specs/source-date-epoch/) specified by
72the Reproducible Builds project, which can be set to a UNIX epoch timestamp.
73This will be used for the build timestamps embedded in compiled Go binaries,
74and maybe someday also Docker images.
75
76One reasonable setting for this variable is to use the commit timestamp from the
77tip of the tree being built; this is what the Kubernetes CI system uses. For
78example, you could use the following one-liner:
79
80```bash
81SOURCE_DATE_EPOCH=$(git show -s --format=format:%ct HEAD)
82```
83