Generating Reference Documentation for the Kubernetes API

This page shows how to update the Kubernetes API reference documentation.

The Kubernetes API reference documentation is built from the Kubernetes OpenAPI spec using the kubernetes-sigs/reference-docs generation code.

If you find bugs in the generated documentation, you need to fix them upstream.

If you need only to regenerate the reference documentation from the OpenAPI spec, continue reading this page.

Before you begin


  • You need a machine that is running Linux or macOS.

  • You need to have these tools installed:

  • Your PATH environment variable must include the required build tools, such as the Go binary and python.

  • You need to know how to create a pull request to a GitHub repository. This involves creating your own fork of the repository. For more information, see Work from a local clone.

Set up the local repositories

Create a local workspace and set your GOPATH:

mkdir -p $HOME/<workspace>

export GOPATH=$HOME/<workspace>

Get a local clone of the following repositories:

go get -u

go get -u
go get -u

If you don't already have the kubernetes/website repository, get it now:

git clone<your-username>/website $GOPATH/src/<your-username>/website

Get a clone of the kubernetes/kubernetes repository as

git clone $GOPATH/src/
  • The base directory of your clone of the kubernetes/kubernetes repository is $GOPATH/src/ The remaining steps refer to your base directory as <k8s-base>.

  • The base directory of your clone of the kubernetes/website repository is $GOPATH/src/<your username>/website. The remaining steps refer to your base directory as <web-base>.

  • The base directory of your clone of the kubernetes-sigs/reference-docs repository is $GOPATH/src/ The remaining steps refer to your base directory as <rdocs-base>.

Generate the API reference docs

This section shows how to generate the published Kubernetes API reference documentation.

Set build variables

  • Set K8S_ROOT to <k8s-base>.
  • Set K8S_WEBROOT to <web-base>.
  • Set K8S_RELEASE to the version of the docs you want to build. For example, if you want to build docs for Kubernetes 1.17.0, set K8S_RELEASE to 1.17.0.

For example:

export K8S_WEBROOT=${GOPATH}/src/<your-username>/website
export K8S_ROOT=${GOPATH}/src/
export K8S_RELEASE=1.17.0

Create versioned directory and fetch Open API spec

The updateapispec build target creates the versioned build directory. After the directory is created, the Open API spec is fetched from the <k8s-base> repository. These steps ensure that the version of the configuration files and Kubernetes Open API spec match the release version. The versioned directory name follows the pattern of v<major>_<minor>.

In the <rdocs-base> directory, run the following build target:

cd <rdocs-base>
make updateapispec

Build the API reference docs

The copyapi target builds the API reference and copies the generated files to directories in <web-base>. Run the following command in <rdocs-base>:

cd <rdocs-base>
make copyapi

Verify that these two files have been generated:

[ -e "<rdocs-base>/gen-apidocs/build/index.html" ] && echo "index.html built" || echo "no index.html"
[ -e "<rdocs-base>/gen-apidocs/build/navData.js" ] && echo "navData.js built" || echo "no navData.js"

Go to the base of your local <web-base>, and view which files have been modified:

cd <web-base>
git status

The output is similar to:


Update the API reference index pages

When generating reference documentation for a new release, update the file, <web-base>/content/en/docs/reference/kubernetes-api/ with the new version number.

  • Open <web-base>/content/en/docs/reference/kubernetes-api/ for editing, and update the API reference version number. For example:

    title: v1.17
    [Kubernetes API v1.17](/docs/reference/generated/kubernetes-api/v1.17/)
  • Open <web-base>/content/en/docs/reference/ for editing, and add a new link for the latest API reference. Remove the oldest API reference version. There should be five links to the most recent API references.

Locally test the API reference

Publish a local version of the API reference. Verify the local preview.

cd <web-base>
git submodule update --init --recursive --depth 1 # if not already done
make container-serve

Commit the changes

In <web-base>, run git add and git commit to commit the change.

Submit your changes as a pull request to the kubernetes/website repository. Monitor your pull request, and respond to reviewer comments as needed. Continue to monitor your pull request until it has been merged.

What's next

Last modified January 02, 2024 at 8:14 PM PST: Clean up three generate-ref-docs (4d6a8e57c0)