2018-01-11 20:43:28 +00:00
|
|
|
|
---
|
|
|
|
|
title: Generating Reference Documentation for kubectl Commands
|
2018-05-05 16:00:51 +00:00
|
|
|
|
content_template: templates/task
|
2020-02-06 21:53:25 +00:00
|
|
|
|
weight: 90
|
2018-01-11 20:43:28 +00:00
|
|
|
|
---
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture overview %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
This page shows how to generate the `kubectl` command reference.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{< note >}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
This topic shows how to generate reference documentation for
|
|
|
|
|
[kubectl commands](/docs/reference/generated/kubectl/kubectl-commands)
|
|
|
|
|
like
|
|
|
|
|
[kubectl apply](/docs/reference/generated/kubectl/kubectl-commands#apply) and
|
|
|
|
|
[kubectl taint](/docs/reference/generated/kubectl/kubectl-commands#taint).
|
|
|
|
|
This topic does not show how to generate the
|
|
|
|
|
[kubectl](/docs/reference/generated/kubectl/kubectl/)
|
|
|
|
|
options reference page. For instructions on how to generate the kubectl options
|
|
|
|
|
reference page, see
|
|
|
|
|
[Generating Reference Pages for Kubernetes Components and Tools](/docs/home/contribute/generated-reference/kubernetes-components/).
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{< /note >}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% /capture %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture prerequisites %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
{{< include "prerequisites-ref-docs.md" >}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% /capture %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture steps %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
## Setting up the local repositories
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
Create a local workspace and set your `GOPATH`.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
2019-07-06 11:54:35 +00:00
|
|
|
|
mkdir -p $HOME/<workspace>
|
|
|
|
|
|
|
|
|
|
export GOPATH=$HOME/<workspace>
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
Get a local clone of the following repositories:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
go get -u github.com/spf13/pflag
|
|
|
|
|
go get -u github.com/spf13/cobra
|
|
|
|
|
go get -u gopkg.in/yaml.v2
|
2020-03-17 20:05:27 +00:00
|
|
|
|
go get -u github.com/kubernetes-sigs/reference-docs
|
2019-07-06 11:54:35 +00:00
|
|
|
|
```
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
If you don't already have the kubernetes/website repository, get it now:
|
|
|
|
|
|
|
|
|
|
```shell
|
2019-07-06 11:54:35 +00:00
|
|
|
|
git clone https://github.com/<your-username>/website $GOPATH/src/github.com/<your-username>/website
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
Get a clone of the kubernetes/kubernetes repository as k8s.io/kubernetes:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes
|
|
|
|
|
```
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
Remove the spf13 package from `$GOPATH/src/k8s.io/kubernetes/vendor/github.com`.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
2019-07-06 11:54:35 +00:00
|
|
|
|
rm -rf $GOPATH/src/k8s.io/kubernetes/vendor/github.com/spf13
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
The kubernetes/kubernetes repository provides the `kubectl` and `kustomize` source code.
|
2019-07-06 11:54:35 +00:00
|
|
|
|
|
|
|
|
|
* Determine the base directory of your clone of the
|
|
|
|
|
[kubernetes/kubernetes](https://github.com/kubernetes/kubernetes) repository.
|
|
|
|
|
For example, if you followed the preceding step to get the repository, your
|
|
|
|
|
base directory is `$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
|
|
|
|
|
[kubernetes/website](https://github.com/kubernetes/website) repository.
|
|
|
|
|
For example, if you followed the preceding step to get the repository, your
|
|
|
|
|
base directory is `$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
|
2019-09-30 19:42:46 +00:00
|
|
|
|
[kubernetes-sigs/reference-docs](https://github.com/kubernetes-sigs/reference-docs) repository.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
For example, if you followed the preceding step to get the repository, your
|
2019-09-30 19:42:46 +00:00
|
|
|
|
base directory is `$GOPATH/src/github.com/kubernetes-sigs/reference-docs.`
|
2018-01-11 20:43:28 +00:00
|
|
|
|
The remaining steps refer to your base directory as `<rdocs-base>`.
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
In your local k8s.io/kubernetes repository, check out the branch of interest,
|
2018-01-11 20:43:28 +00:00
|
|
|
|
and make sure it is up to date. For example, if you want to generate docs for
|
2020-02-06 21:53:25 +00:00
|
|
|
|
Kubernetes 1.17, you could use these commands:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
cd <k8s-base>
|
2020-02-06 21:53:25 +00:00
|
|
|
|
git checkout v1.17.0
|
|
|
|
|
git pull https://github.com/kubernetes/kubernetes v1.17.0
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
If you do not need to edit the `kubectl` source code, follow the instructions for
|
|
|
|
|
[Setting build variables](#setting-build-variables).
|
2019-07-06 11:54:35 +00:00
|
|
|
|
|
2018-01-11 20:43:28 +00:00
|
|
|
|
## Editing the kubectl source code
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
The kubectl command reference documentation is automatically generated from
|
|
|
|
|
the kubectl source code. If you want to change the reference documentation, the first step
|
2018-01-11 20:43:28 +00:00
|
|
|
|
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
|
|
|
|
|
[github.com/kubernetes/kubernetes](https://github.com/kubernetes/kubernetes).
|
|
|
|
|
|
|
|
|
|
[PR 56673](https://github.com/kubernetes/kubernetes/pull/56673/files)
|
|
|
|
|
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 master branch of the kubernetes/kubernetes repository.
|
|
|
|
|
|
|
|
|
|
## Cherry picking your change into a release branch
|
|
|
|
|
|
|
|
|
|
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.10,
|
2019-07-06 11:54:35 +00:00
|
|
|
|
and you want to backport your change to the release-1.15 branch. For instructions
|
2018-01-11 20:43:28 +00:00
|
|
|
|
on how to do this, see
|
2019-05-16 11:51:43 +00:00
|
|
|
|
[Propose a Cherry Pick](https://git.k8s.io/community/contributors/devel/sig-release/cherry-picks.md).
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
Monitor your cherry-pick pull request until it is merged into the release branch.
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{< note >}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
Proposing a cherry pick requires that you have permission to set a label and a
|
|
|
|
|
milestone in your pull request. If you don’t have those permissions, you will
|
|
|
|
|
need to work with someone who can set the label and milestone for you.
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{< /note >}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
## Setting build variables
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
Go to `<rdocs-base>`. On you command line, set the following environment variables.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
* Set `K8S_ROOT` to `<k8s-base>`.
|
2020-03-17 20:05:27 +00:00
|
|
|
|
* Set `K8S_WEBROOT` to `<web-base>`.
|
2020-02-06 21:53:25 +00:00
|
|
|
|
* 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, set `K8S_RELEASE` to 1.17.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
For example:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
```shell
|
2020-03-17 20:05:27 +00:00
|
|
|
|
export K8S_WEBROOT=$GOPATH/src/github.com/<your-username>/website
|
|
|
|
|
export K8S_ROOT=$GOPATH/src/k8s.io/kubernetes
|
2020-02-06 21:53:25 +00:00
|
|
|
|
export K8S_RELEASE=1.17
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
## Creating a versioned directory
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
The `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>`.
|
2019-07-06 11:54:35 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
In the `<rdocs-base>` directory, run the following build target:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
2020-02-06 21:53:25 +00:00
|
|
|
|
cd <rdocs-base>
|
|
|
|
|
make createversiondirs
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
## Checking out a release tag in k8s.io/kubernetes
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
In your local `<k8s-base>` repository, checkout the branch that has
|
2018-01-11 20:43:28 +00:00
|
|
|
|
the version of Kubernetes that you want to document. For example, if you want
|
2020-02-06 21:53:25 +00:00
|
|
|
|
to generate docs for Kubernetes 1.17, checkout the `v1.17.0` tag. Make sure
|
2018-01-11 20:43:28 +00:00
|
|
|
|
you local branch is up to date.
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
```shell
|
|
|
|
|
cd <k8s-base>
|
2020-02-06 21:53:25 +00:00
|
|
|
|
git checkout v1.17.0
|
|
|
|
|
git pull https://github.com/kubernetes/kubernetes v1.17.0
|
2019-07-06 11:54:35 +00:00
|
|
|
|
```
|
|
|
|
|
|
2018-01-11 20:43:28 +00:00
|
|
|
|
## Running the doc generation code
|
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
In your local `<rdocs-base>`, run the `copycli` build target. The command runs as `root`:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
cd <rdocs-base>
|
2019-07-06 11:54:35 +00:00
|
|
|
|
make copycli
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
The `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>`.
|
2019-07-06 11:54:35 +00:00
|
|
|
|
|
2018-01-11 20:43:28 +00:00
|
|
|
|
## Locate the generated files
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
Verify that these two files have been generated:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
```shell
|
|
|
|
|
[ -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"
|
|
|
|
|
```
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
## Locate the copied files
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
Verify that all generated files have been copied to your `<web-base>`:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
2019-07-06 11:54:35 +00:00
|
|
|
|
cd <web-base>
|
|
|
|
|
git status
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
The output should include the modified files:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
static/docs/reference/generated/kubectl/kubectl-commands.html
|
|
|
|
|
static/docs/reference/generated/kubectl/navData.js
|
|
|
|
|
```
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
The output may also include:
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```
|
2019-07-06 11:54:35 +00:00
|
|
|
|
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
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
## Locally test the documentation
|
|
|
|
|
|
|
|
|
|
Build the Kubernetes documentation in your local `<web-base>`.
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
|
|
|
|
```shell
|
2019-07-06 11:54:35 +00:00
|
|
|
|
cd <web-base>
|
|
|
|
|
make docker-serve
|
2018-01-11 20:43:28 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-07-06 11:54:35 +00:00
|
|
|
|
View the [local preview](https://localhost:1313/docs/reference/generated/kubectl/kubectl-commands/).
|
|
|
|
|
|
|
|
|
|
## Adding and committing changes in kubernetes/website
|
|
|
|
|
|
2018-01-11 20:43:28 +00:00
|
|
|
|
Run `git add` and `git commit` to commit the files.
|
|
|
|
|
|
|
|
|
|
## Creating a pull request
|
|
|
|
|
|
|
|
|
|
Create a pull request to the `kubernetes/website` repository. Monitor your
|
|
|
|
|
pull request, and respond to review comments as needed. Continue to monitor
|
|
|
|
|
your pull request until it is merged.
|
|
|
|
|
|
|
|
|
|
A few minutes after your pull request is merged, your updated reference
|
|
|
|
|
topics will be visible in the
|
|
|
|
|
[published documentation](/docs/home).
|
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% /capture %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
|
{{% capture whatsnext %}}
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2020-02-06 21:53:25 +00:00
|
|
|
|
* [Generating Reference Documentation Quickstart](/docs/contribute/generate-ref-docs/quickstart/)
|
|
|
|
|
* [Generating Reference Documentation for Kubernetes Components and Tools](/docs/contribute/generate-ref-docs/kubernetes-components/)
|
|
|
|
|
* [Generating Reference Documentation for the Kubernetes API](/docs/contribute/generate-ref-docs/kubernetes-api/)
|
2018-01-11 20:43:28 +00:00
|
|
|
|
|
2019-09-30 19:42:46 +00:00
|
|
|
|
{{% /capture %}}
|