Generating Reference Documentation for kubectl Commands
This page shows how to generate the kubectl
command reference.
Before you begin
Requirements:
-
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 theGo
binary andpython
. -
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.
Setting 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 github.com/spf13/pflag
go get -u github.com/spf13/cobra
go get -u gopkg.in/yaml.v2
go get -u github.com/kubernetes-sigs/reference-docs
If you don't already have the kubernetes/website repository, get it now:
git clone https://github.com/<your-username>/website $GOPATH/src/github.com/<your-username>/website
Get a clone of the kubernetes/kubernetes repository as k8s.io/kubernetes:
git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes
Remove the spf13 package from $GOPATH/src/k8s.io/kubernetes/vendor/github.com
.
rm -rf $GOPATH/src/k8s.io/kubernetes/vendor/github.com/spf13
The kubernetes/kubernetes repository provides the kubectl
and kustomize
source code.
-
Determine the base directory of your clone of the $GOPATH/src/k8s.io/kubernetes. The remaining steps refer to your base directory as
<k8s-base>
. -
Determine the base directory of your clone of the $GOPATH/src/github.com/<your-username>/website. The remaining steps refer to your base directory as
<web-base>
. -
Determine the base directory of your clone of the $GOPATH/src/github.com/kubernetes-sigs/reference-docs. The remaining steps refer to your base directory as
<rdocs-base>
.
In your local k8s.io/kubernetes repository, check out the branch of interest, and make sure it is up to date. For example, if you want to generate docs for Kubernetes 1.26.0, you could use these commands:
cd <k8s-base>
git checkout v1.26.0
git pull https://github.com/kubernetes/kubernetes 1.26.0
If you do not need to edit the kubectl
source code, follow the instructions for
Setting build variables.
Editing the kubectl source code
The kubectl command reference documentation is automatically generated from
the kubectl source code. If you want to change the reference documentation, the first step
is to change one or more comments in the kubectl source code. Make the change in your
local kubernetes/kubernetes repository, and then submit a pull request to the master branch of
is an example of a pull request that fixes a typo in the kubectl source code. Monitor your pull request, and respond to reviewer comments. Continue to monitor your
pull request until it is merged into the target branch of the kubernetes/kubernetes repository. Your change is now in the master branch, which is used for development of the next
Kubernetes release. If you want your change to appear in the docs for a Kubernetes
version that has already been released, you need to propose that your change be
cherry picked into the release branch. For example, suppose the master branch is being used to develop Kubernetes
1.23
and you want to backport your change to the release-1.26 branch. For
instructions on how to do this, see
. Monitor your cherry-pick pull request until it is merged into the release branch. Go to For example: The In the In your local In your local The Verify that these two files have been generated: Verify that all generated files have been copied to your The output should include the modified files: The output may also include: Build the Kubernetes documentation in your local View the . Run Create a pull request to the A few minutes after your pull request is merged, your updated reference
topics will be visible in the
published documentation.Cherry picking your change into a release branch
Setting build variables
<rdocs-base>
. On you command line, set the following environment variables.
K8S_ROOT
to <k8s-base>
.K8S_WEBROOT
to <web-base>
.K8S_RELEASE
to the version of the docs you want to build.
For example, if you want to build docs for Kubernetes 1.26, set K8S_RELEASE
to 1.26.export K8S_WEBROOT=$GOPATH/src/github.com/<your-username>/website
export K8S_ROOT=$GOPATH/src/k8s.io/kubernetes
export K8S_RELEASE=1.26
Creating a versioned directory
createversiondirs
build target creates a versioned directory
and copies the kubectl reference configuration files to the versioned directory.
The versioned directory name follows the pattern of v<major>_<minor>
.<rdocs-base>
directory, run the following build target:cd <rdocs-base>
make createversiondirs
Checking out a release tag in k8s.io/kubernetes
<k8s-base>
repository, checkout the branch that has
the version of Kubernetes that you want to document. For example, if you want
to generate docs for Kubernetes 1.26.0, check out the
v1.26
tag. Make sure
you local branch is up to date.cd <k8s-base>
git checkout v1.26.0
git pull https://github.com/kubernetes/kubernetes v1.26.0
Running the doc generation code
<rdocs-base>
, run the copycli
build target. The command runs as root
:cd <rdocs-base>
make copycli
copycli
command cleans the temporary build directory, generates the kubectl command files,
and copies the collated kubectl command reference HTML page and assets to <web-base>
.Locate the generated files
[ -e "<rdocs-base>/gen-kubectldocs/generators/build/index.html" ] && echo "index.html built" || echo "no index.html"
[ -e "<rdocs-base>/gen-kubectldocs/generators/build/navData.js" ] && echo "navData.js built" || echo "no navData.js"
Locate the copied files
<web-base>
:cd <web-base>
git status
static/docs/reference/generated/kubectl/kubectl-commands.html
static/docs/reference/generated/kubectl/navData.js
static/docs/reference/generated/kubectl/scroll.js
static/docs/reference/generated/kubectl/stylesheet.css
static/docs/reference/generated/kubectl/tabvisibility.js
static/docs/reference/generated/kubectl/node_modules/bootstrap/dist/css/bootstrap.min.css
static/docs/reference/generated/kubectl/node_modules/highlight.js/styles/default.css
static/docs/reference/generated/kubectl/node_modules/jquery.scrollto/jquery.scrollTo.min.js
static/docs/reference/generated/kubectl/node_modules/jquery/dist/jquery.min.js
static/docs/reference/generated/kubectl/node_modules/font-awesome/css/font-awesome.min.css
Locally test the documentation
<web-base>
.cd <web-base>
git submodule update --init --recursive --depth 1 # if not already done
make container-serve
Adding and committing changes in kubernetes/website
git add
and git commit
to commit the files.Creating a pull request
kubernetes/website
repository. Monitor your
pull request, and respond to review comments as needed. Continue to monitor
your pull request until it is merged.What's next