2018-01-11 20:43:28 +00:00
---
title: Generating Reference Pages for Kubernetes Components and Tools
2018-05-05 16:00:51 +00:00
content_template: templates/task
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
This page shows how to use the `update-imported-docs` tool to generate
reference documentation for tools and components in the
2019-09-24 07:59:25 +00:00
[Kubernetes ](https://github.com/kubernetes/kubernetes ) repository.
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
2018-07-18 22:12:16 +00:00
* You need a machine that is running Linux or macOS.
2018-01-11 20:43:28 +00:00
2019-10-22 21:04:18 +00:00
* Install the following:
2018-01-11 20:43:28 +00:00
2019-10-22 21:04:18 +00:00
* [Python ](https://www.python.org/downloads/ ) v3.7.x
2018-01-11 20:43:28 +00:00
* [Git ](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git )
2019-10-14 23:19:52 +00:00
* [Golang ](https://golang.org/doc/install ) version 1.12 for Kubernetes 1.14+; Go 1.13 [is not supported ](https://github.com/kubernetes/community/blob/master/contributors/devel/development.md#go )
2019-10-22 21:04:18 +00:00
* [Pip ](https://pypi.org/project/pip/ ) used to install PyYAML
* [PyYAML ](https://pyyaml.org/ ) v5.1.2
2018-01-11 20:43:28 +00:00
* [make ](https://www.gnu.org/software/make/ )
* [gcc compiler/linker ](https://gcc.gnu.org/ )
2019-10-22 21:04:18 +00:00
* The `Go` binary must be in your path. The `update-imported-docs` tool sets your GOPATH.
2018-01-11 20:43:28 +00:00
* You need to know how to create a pull request to a GitHub repository.
2019-10-14 23:19:52 +00:00
This involves creating your own fork of the repository. For more
information, see [Work from a local clone ](/docs/contribute/intermediate/#work_from_a_local_clone ).
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-10-14 23:19:52 +00:00
## Getting the repository
2018-01-11 20:43:28 +00:00
2019-10-14 23:19:52 +00:00
Make sure your `website` fork is up-to-date with the `kubernetes/website` master and then clone your `website` fork.
2018-01-11 20:43:28 +00:00
```shell
2019-10-14 23:19:52 +00:00
mkdir github.com
cd github.com
git clone git@github.com:< your_github_username > /website.git
2018-01-11 20:43:28 +00:00
```
2019-10-14 23:19:52 +00:00
Determine the base directory of your clone. For example, if you followed the
preceding step to get the repository, your base directory is
2019-10-22 21:04:18 +00:00
`github.com/website.` The remaining steps refer to your base directory as
2019-10-14 23:19:52 +00:00
`<web-base>` .
2018-01-11 20:43:28 +00:00
2019-10-22 21:04:18 +00:00
The `update-imported-docs` tool generates the reference documentation for the
Kubernetes components from the Kubernetes source code. The tool automatically
2019-10-14 23:19:52 +00:00
clones the `kubernetes/kubernetes` repository. If you want to change the
reference documentation, please follow [this
guide](/docs/contribute/generate-ref-docs/contribute-upstream).
2018-01-11 20:43:28 +00:00
## Overview of update-imported-docs
2018-11-20 01:54:07 +00:00
The `update-imported-docs` tool is located in the `kubernetes/website/update-imported-docs/`
2019-10-14 23:19:52 +00:00
directory. The tool consists of a Python script that reads a YAML configuration file and performs the following steps:
2018-09-21 21:08:50 +00:00
1. Clones the related repositories specified in a configuration file. For the
2019-09-24 07:59:25 +00:00
purpose of generating reference docs, the repository that is cloned by
2019-09-30 19:42:46 +00:00
default is `kubernetes-sigs/reference-docs` .
2018-09-21 21:08:50 +00:00
1. Runs commands under the cloned repositories to prepare the docs generator and
then generates the Markdown files.
1. Copies the generated Markdown files to a local clone of the `kubernetes/website`
repository under locations specified in the configuration file.
2019-09-24 07:59:25 +00:00
1. Updates `kubectl` command links from `kubectl` .md to the `kubectl` command reference.
2018-09-21 21:08:50 +00:00
When the Markdown files are in your local clone of the `kubernetes/website`
2019-04-19 19:45:54 +00:00
repository, you can submit them in a [pull request ](/docs/contribute/start/ )
2018-01-11 20:43:28 +00:00
to `kubernetes/website` .
2019-10-14 23:19:52 +00:00
## Configuration file format
2019-10-22 21:04:18 +00:00
Each config file may contain multiple repos that will be imported together. When
necessary, you can customize the configuration file by manually editing it. You
may create new config files for importing other groups of documents. Imported
documents must follow these guidelines:
2019-10-14 23:19:52 +00:00
1. Adhere to the [Documentation Style Guide ](/docs/contribute/style/style-guide/ ).
1. Have `title` defined in the front matter. For example:
```
---
title: Title Displayed in Table of Contents
---
Rest of the .md file...
```
1. Be listed in the `kubernetes/website/data/reference.yml` file
The following is an example of the YAML configuration file:
```yaml
repos:
- name: community
remote: https://github.com/kubernetes/community.git
branch: master
files:
- src: contributors/devel/README.md
dst: docs/imported/community/devel.md
- src: contributors/guide/README.md
dst: docs/imported/community/guide.md
```
Note: `generate-command` is an optional entry, which can be used to run a
given command or a short script to generate the docs from within a repo.
## Customizing the reference.yml config file
2018-01-11 20:43:28 +00:00
2018-11-20 01:54:07 +00:00
Open `<web-base>/update-imported-docs/reference.yml` for editing.
Do not change the content for the `generate-command` entry unless you understand
2018-09-21 21:08:50 +00:00
what it is doing and need to change the specified release branch.
2018-01-11 20:43:28 +00:00
2019-06-17 01:04:07 +00:00
```yaml
2018-01-11 20:43:28 +00:00
repos:
2018-09-21 21:08:50 +00:00
- name: reference-docs
2019-09-30 19:42:46 +00:00
remote: https://github.com/kubernetes-sigs/reference-docs.git
2018-09-21 21:08:50 +00:00
# This and the generate-command below needs a change when reference-docs has
# branches properly defined
2019-06-17 01:04:07 +00:00
branch: master
2018-09-21 21:08:50 +00:00
generate-command: |
cd $GOPATH
git clone https://github.com/kubernetes/kubernetes.git src/k8s.io/kubernetes
cd src/k8s.io/kubernetes
2019-10-14 23:19:52 +00:00
git checkout release-1.16
2018-09-21 21:08:50 +00:00
make generated_files
cp -L -R vendor $GOPATH/src
rm -r vendor
cd $GOPATH
2019-09-30 19:42:46 +00:00
go get -v github.com/kubernetes-sigs/reference-docs/gen-compdocs
cd src/github.com/kubernetes-sigs/reference-docs/
2018-09-21 21:08:50 +00:00
make comp
2018-01-11 20:43:28 +00:00
```
2018-11-20 01:54:07 +00:00
In reference.yml, the `files` field is a list of `src` and `dst` fields. The `src` field
specifies the location of a generated Markdown file, and the `dst` field specifies
where to copy this file in the cloned `kubernetes/website` repository.
2018-09-21 21:08:50 +00:00
For example:
2018-01-11 20:43:28 +00:00
2018-09-21 21:08:50 +00:00
```yaml
2018-01-11 20:43:28 +00:00
repos:
2018-09-21 21:08:50 +00:00
- name: reference-docs
2019-09-30 19:42:46 +00:00
remote: https://github.com/kubernetes-sigs/reference-docs.git
2018-01-11 20:43:28 +00:00
files:
2018-09-21 21:08:50 +00:00
- src: gen-compdocs/build/kube-apiserver.md
dst: content/en/docs/reference/command-line-tools-reference/kube-apiserver.md
2018-01-11 20:43:28 +00:00
...
```
2018-09-21 21:08:50 +00:00
Note that when there are many files to be copied from the same source directory
to the same destination directory, you can use wildcards in the value given to
`src` and you can just provide the directory name as the value for `dst` .
For example:
2018-01-11 20:43:28 +00:00
2019-06-17 01:04:07 +00:00
```yaml
2018-01-11 20:43:28 +00:00
files:
2018-09-21 21:08:50 +00:00
- src: gen-compdocs/build/kubeadm*.md
dst: content/en/docs/reference/setup-tools/kubeadm/generated/
2018-01-11 20:43:28 +00:00
```
## Running the update-imported-docs tool
2018-09-21 21:08:50 +00:00
After having reviewed and/or customized the `reference.yaml` file, you can run
the `update-imported-docs` tool:
2018-01-11 20:43:28 +00:00
```shell
2018-09-21 21:08:50 +00:00
cd < web-base > /update-imported-docs
./update-imported-docs reference.yml
2018-01-11 20:43:28 +00:00
```
2019-10-14 23:19:52 +00:00
## Fixing Links
To fix relative links within your imported files, set the repo config's
`gen-absolute-links` property to `true` . You can find an example of this in
[`release.yml` ](https://github.com/kubernetes/website/blob/master/update-imported-docs/release.yml ).
2018-01-11 20:43:28 +00:00
## Adding and committing changes in kubernetes/website
List the files that were generated and copied to the `kubernetes/website`
repository:
```
cd < web-base >
git status
```
The output shows the new and modified files. For example, the output
might look like this:
```shell
...
2018-09-21 21:08:50 +00:00
modified: content/en/docs/reference/command-line-tools-reference/cloud-controller-manager.md
modified: content/en/docs/reference/command-line-tools-reference/kube-apiserver.md
modified: content/en/docs/reference/command-line-tools-reference/kube-controller-manager.md
modified: content/en/docs/reference/command-line-tools-reference/kube-proxy.md
modified: content/en/docs/reference/command-line-tools-reference/kube-scheduler.md
2019-09-24 07:59:25 +00:00
modified: content/en/docs/reference/setup-tools/kubeadm/generated/kubeadm.md
modified: content/en/docs/reference/kubectl/kubectl.md
2018-09-21 21:08:50 +00:00
...
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
2019-09-24 07:59:25 +00:00
* [Generating Reference Documentation for kubectl Commands ](/docs/contribute/generate-ref-docs/kubectl/ )
* [Generating Reference Documentation for the Kubernetes API ](/docs/contribute/generate-ref-docs/kubernetes-api/ )
* [Contributing to the Upstream Kubernetes Project for Documentation ](/docs/contribute/generate-ref-docs/contribute-upstream/ )
2019-04-19 19:45:54 +00:00
{{% /capture %}}