# 定制 Hugo 短代码

LLMS index: [llms.txt](/llms.txt)

---

<!--
title: Custom Hugo Shortcodes
content_type: concept
weight: 120
-->

<!-- overview -->

<!--
This page explains the custom Hugo shortcodes that can be used in Kubernetes Markdown documentation.
-->
本页面将介绍 Hugo 自定义短代码，可以用于 Kubernetes Markdown 文档书写。

<!--
Read more about shortcodes in the [Hugo documentation](https://gohugo.io/content-management/shortcodes).
-->
关于短代码的更多信息可参见
[Hugo 文档](https://gohugo.io/content-management/shortcodes)。

<!-- body -->

<!--
## Feature state

In a Markdown page (`.md` file) on this site, you can add a shortcode to
display version and state of the documented feature.
-->
## 功能状态 {#feature-state}

在本站的 Markdown 页面（`.md` 文件）中，你可以加入短代码来展示所描述的功能特性的版本和状态。

<!--
### Feature state demo

Below is a demo of the feature state snippet, which displays the feature as
stable in the latest Kubernetes version.
-->
### 功能状态示例 {#feature-state-demo}

下面是一个功能状态代码段的演示，表明这个功能已经在最新版 Kubernetes 中稳定了。

```
{{< feature-state state="stable" >}}
```

<!--
Renders to:
-->
会转换为：








  <div class="feature-state-notice feature-stable">
      <span class="feature-state-name">特性状态：</span>
      <code>Kubernetes v1.36 [stable]</code>
    </div>
  



<!--
The valid values for `state` are:
-->
`state` 的可选值如下：

* alpha
* beta
* deprecated
* stable

<!--
### Feature state code

The displayed Kubernetes version defaults to that of the page or the site. You can change the
feature state version by passing the `for_k8s_version` shortcode parameter. For example:
-->
### 功能状态代码 {#feature-state-code}

所显示的 Kubernetes 默认为该页或站点版本。
修改 <code>for_k8s_version</code> 短代码参数可以调整要显示的版本。例如：

```
{{< feature-state for_k8s_version="v1.10" state="beta" >}}
```

<!--
Renders to:
-->
会转换为：








  <div class="feature-state-notice feature-beta">
      <span class="feature-state-name">特性状态：</span>
      <code>Kubernetes v1.10 [beta]</code>
    </div>
  



<!--
### Feature state retrieval from description file

To dynamically determine the state of the feature, make use of the `feature_gate_name`
shortcode parameter. The feature state details will be extracted from the corresponding feature gate 
description file located in `content/en/docs/reference/command-line-tools-reference/feature-gates/`.
For example:
-->
### 从描述文件中检索特征状态

要动态确定特性的状态，请使用 `feature_gate_name` 短代码参数，此参数将从
`content/en/docs/reference/command-line-tools-reference/feature-gates/`
中相应的特性门控描述文件中提取特性的详细状态信息。

例如：

```
{{< feature-state feature_gate_name="NodeSwap" >}}
```

<!--
Renders to:
-->
会转换为：








  <div class="feature-state-notice feature-stable" title="特性门控： NodeSwap">
              <span class="feature-state-name">特性状态：</span> 
              <code>Kubernetes v1.34 [stable]</code>（默认启用）</div>


<!--
## Feature gate description

In a Markdown page (`.md` file) on this site, you can add a shortcode to
display the description for a shortcode.
-->
## 特性门控介绍

在此站点上的 Markdown 页面（`.md` 文件）中，你可以添加短代码来显示短代码的描述。

<!--
### Feature gate description demo

Below is a demo of the feature state snippet, which displays the feature as
stable in the latest Kubernetes version.
-->
### 特性门控 Demo 演示

下面是特性状态片段的 Demo，它显示该特性在最新的 Kubernetes 版本中处于稳定状态。

```
{{< feature-gate-description name="DryRun" >}}
```

<!--
Renders to:
-->
会转换为：

<p><code>DryRun</code>: <!--
Enable server-side [dry run](/docs/reference/using-api/api-concepts/#dry-run) requests
so that validation, merging, and mutation can be tested without committing.
-->
<p>启用在服务器端对请求进行
<a href="/zh-cn/docs/reference/using-api/api-concepts/#dry-run">试运行（Dry Run）</a>，
以便在不提交的情况下测试验证、合并和变更。</p></p>

<!--
## Glossary
There are two glossary shortcodes: `glossary_tooltip` and `glossary_definition`.

You can reference glossary terms with an inclusion that automatically updates
and replaces content with the relevant links from [our glossary](/docs/reference/glossary/).
When the glossary term is moused-over, the glossary entry displays a tooltip.
The glossary term also displays as a link.

As well as inclusions with tooltips, you can reuse the definitions from the glossary in
page content.
-->
## 词汇 {#glossary}

有两种词汇表提示：`glossary_tooltip` 和 `glossary_definition`。

你可以通过加入术语词汇的短代码，来自动更新和替换相应链接中的内容
（[我们的词汇库](/zh-cn/docs/reference/glossary/)）
在浏览在线文档时，术语会显示为超链接的样式，当鼠标移到术语上时，其解释就会显示在提示框中。

除了包含工具提示外，你还可以重用页面内容中词汇表中的定义。

<!--
The raw data for glossary terms is stored at
[the glossary directory](https://github.com/kubernetes/website/tree/main/content/en/docs/reference/glossary),
with a content file for each glossary term.
-->
词汇术语的原始数据保存在[词汇目录](https://github.com/kubernetes/website/tree/main/content/en/docs/reference/glossary)，
每个内容文件对应相应的术语解释。

<!--
### Glossary demo

For example, the following include within the Markdown renders to
<a class='glossary-tooltip' title='一组工作机器，称为节点，会运行容器化应用程序。每个集群至少有一个工作节点。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/reference/glossary/?all=true#term-cluster' target='_blank' aria-label='cluster'>cluster</a> with a tooltip:
-->
### 词汇演示 {#glossary-demo}

例如下面的代码在 Markdown 中将会转换为
<a class='glossary-tooltip' title='一组工作机器，称为节点，会运行容器化应用程序。每个集群至少有一个工作节点。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/reference/glossary/?all=true#term-cluster' target='_blank' aria-label='cluster'>cluster</a>，然后在提示框中显示。

```
{{< glossary_tooltip text="cluster" term_id="cluster" >}}
```
<!--
Here's a short glossary definition:
-->
这是一个简短的词汇表定义：

```
{{< glossary_definition prepend="A cluster is" term_id="cluster" length="short" >}}
```

<!--
which renders as:
<p>A cluster is 一组工作机器，称为<a class='glossary-tooltip' title='Kubernetes 中的工作机器称作节点。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/architecture/nodes/' target='_blank' aria-label='节点'>节点</a>，
会运行容器化应用程序。每个集群至少有一个工作节点。</p>
-->
呈现为：

<p>A cluster is 一组工作机器，称为<a class='glossary-tooltip' title='Kubernetes 中的工作机器称作节点。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/architecture/nodes/' target='_blank' aria-label='节点'>节点</a>，
会运行容器化应用程序。每个集群至少有一个工作节点。</p>

<!--
You can also include a full definition:
-->
你也可以包括完整的定义：

```
{{< glossary_definition term_id="cluster" length="all" >}}
```

<!--
which renders as:
-->
呈现为：

<!-- 
title: Cluster
id: cluster
full_link: 
short_description: >
   A set of worker machines, called nodes, that run containerized applications. Every cluster has at least one worker node.

aka: 
tags:
- fundamental
- operation
-->
<!-- 
A set of worker machines, called <a class='glossary-tooltip' title='Kubernetes 中的工作机器称作节点。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/architecture/nodes/' target='_blank' aria-label='nodes'>nodes</a>,
that run containerized applications. Every cluster has at least one worker node.
-->
<p>一组工作机器，称为<a class='glossary-tooltip' title='Kubernetes 中的工作机器称作节点。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/architecture/nodes/' target='_blank' aria-label='节点'>节点</a>，
会运行容器化应用程序。每个集群至少有一个工作节点。</p>
<!-- 
The worker node(s) host the <a class='glossary-tooltip' title='Pod 表示你的集群上一组正在运行的容器。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/workloads/pods/' target='_blank' aria-label='Pods'>Pods</a> that are
the components of the application workload. The
<a class='glossary-tooltip' title='控制平面是指容器编排层，它暴露 API 和接口来定义、部署容器和管理容器的生命周期。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/reference/glossary/?all=true#term-control-plane' target='_blank' aria-label='control plane'>control plane</a> manages the worker
nodes and the Pods in the cluster. In production environments, the control plane usually
runs across multiple computers and a cluster usually runs multiple nodes, providing
fault-tolerance and high availability.
-->
<p>工作节点会托管 <a class='glossary-tooltip' title='Pod 表示你的集群上一组正在运行的容器。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/concepts/workloads/pods/' target='_blank' aria-label='Pod'>Pod</a>，而 Pod 就是作为应用负载的组件。
<a class='glossary-tooltip' title='控制平面是指容器编排层，它暴露 API 和接口来定义、部署容器和管理容器的生命周期。' data-bs-toggle='tooltip' data-bs-placement='top' href='/zh-cn/docs/reference/glossary/?all=true#term-control-plane' target='_blank' aria-label='控制平面'>控制平面</a>管理集群中的工作节点和 Pod。
在生产环境中，控制平面通常跨多台计算机运行，
一个集群通常运行多个节点，提供容错性和高可用性。</p>

<!--
## Links to API Reference
-->
## 链接至 API 参考 {#links-to-api-reference}

<!--
You can link to a page of the Kubernetes API reference using the
`api-reference` shortcode, for example to the








<a href="/docs/reference/kubernetes-api/core/pod-v1/">Pod</a> reference:
-->
你可以使用 `api-reference` 短代码链接到 Kubernetes API 参考页面，例如：








<a href="/docs/reference/kubernetes-api/core/pod-v1/">Pod</a> 参考文件：

```
{{< api-reference page="core/pod-v1" >}}
```

<!--
The content of the `page` parameter is the suffix of the URL of the API reference page.
-->
本语句中 `page` 参数的内容是 API 参考页面的 URL 后缀。

<!--
You can link to a specific place into a page by specifying an `anchor`
parameter, for example to the 







<a href="/docs/reference/kubernetes-api/core/pod-v1/#PodSpec">PodSpec</a>
reference or the 







<a href="/docs/reference/kubernetes-api/core/pod-v1/#environment-variables">environment-variables</a>
section of the page:
-->
你可以通过指定 `anchor` 参数链接到页面中的特定位置，例如到








<a href="/docs/reference/kubernetes-api/core/pod-v1/#PodSpec">PodSpec</a> 参考，或页面的








<a href="/docs/reference/kubernetes-api/core/pod-v1/#environment-variables">environment-variables</a>
部分：

```
{{< api-reference page="core/pod-v1" anchor="PodSpec" >}}
{{< api-reference page="core/pod-v1" anchor="environment-variables" >}}
```

<!--
You can change the text of the link by specifying a `text` parameter, for
example by linking to the








<a href="/docs/reference/kubernetes-api/core/pod-v1/#environment-variables">Environment Variables</a>
section of the page:

```
{{< api-reference page="core/pod-v1" anchor="environment-variables" text="Environment Variable" >}}
```
-->
你可以通过指定 `text` 参数来更改链接的文本，
例如通过链接到页面的







<a href="/docs/reference/kubernetes-api/core/pod-v1/#environment-variables">环境变量</a>部分：

```
{{< api-reference page="core/pod-v1" anchor="environment-variables" text="环境变量" >}}
```

<!--
## Table captions

You can make tables more accessible to screen readers by adding a table caption. To add a
[caption](https://www.w3schools.com/tags/tag_caption.asp) to a table,
enclose the table with a `table` shortcode and specify the caption with the `caption` parameter.
-->
## 表格标题  {#table-captions}

通过添加表格标题，你可以让表格能够被屏幕阅读器读取。
要向表格添加[标题（Caption）](https://www.w3schools.com/tags/tag_caption.asp)，
可用 `table` 短代码包围表格定义，并使用 `caption` 参数给出表格标题。


<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
Table captions are visible to screen readers but invisible when viewed in standard HTML.
-->
<p>表格标题对屏幕阅读器是可见的，但在标准 HTML 中查看时是不可见的。</p></div>


<!--
Here's an example:
-->
下面是一个例子：

<!--
```go-html-template
{{< table caption="Configuration parameters" >}}
Parameter | Description | Default
:---------|:------------|:-------
`timeout` | The timeout for requests | `30s`
`logLevel` | The log level for log output | `INFO`
{{< /table >}}
```
-->
```go-html-template
{{< table caption="配置参数" >}}
参数      | 描述        | 默认值
:---------|:------------|:-------
`timeout` | 请求的超时时长 | `30s`
`logLevel` | 日志输出的级别 | `INFO`
{{< /table >}}
```

<!--
The rendered table looks like this:
-->
所渲染的表格如下：

<!--


 





Parameter | Description | Default
<code>timeout</code> | The timeout for requests | <code>30s</code>
<code>logLevel</code> | The log level for log output | <code>INFO</code>
-->


 





<table><caption style="display: none;">配置参数</caption>
	<thead>
			<tr>
					<th style="text-align: left">参数</th>
					<th style="text-align: left">描述</th>
					<th style="text-align: left">默认值</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td style="text-align: left"><code>timeout</code></td>
					<td style="text-align: left">请求的超时时长</td>
					<td style="text-align: left"><code>30s</code></td>
			</tr>
			<tr>
					<td style="text-align: left"><code>logLevel</code></td>
					<td style="text-align: left">日志输出的级别</td>
					<td style="text-align: left"><code>INFO</code></td>
			</tr>
	</tbody>
</table>


<!--
If you inspect the HTML for the table, you should see this element immediately
after the opening `<table>` element:

```html
<caption style="display: none;">Configuration parameters</caption>
```
-->
如果你查看表格的 HTML 输出结果，你会看到 `<table>`
元素后面紧接着下面的元素：

```html
<caption style="display: none;">配置参数</caption>
```

<!--
## Tabs

In a markdown page (`.md` file) on this site, you can add a tab set to display
multiple flavors of a given solution.

The `tabs` shortcode takes these parameters:
-->
## 标签页 {#tabs}

在本站的 Markdown 页面（`.md` 文件）中，你可以加入一个标签页集来显示某解决方案的不同形式。

`tabs` 短代码包含以下参数：

<!--
* `name`: The name as shown on the tab.
* `codelang`: If you provide inner content to the `tab` shortcode, you can tell Hugo
  what code language to use for highlighting.
* `include`: The file to include in the tab. If the tab lives in a Hugo
  [leaf bundle](https://gohugo.io/content-management/page-bundles/#leaf-bundles),
  the file -- which can be any MIME type supported by Hugo -- is looked up in the bundle itself.
  If not, the content page that needs to be included is looked up relative to the current page.
  Note that with the `include`, you do not have any shortcode inner content and must use the
  self-closing syntax. For example,
  `{{< tab name="Content File #1" include="example1" />}}`. The language needs to be specified
  under `codelang` or the language is taken based on the file name.
  Non-content files are code-highlighted by default.
-->
* `name`：标签页上显示的名字。
* `codelang`：如果要在 `tab` 短代码中加入内部内容，需要告知 Hugo 使用的是什么代码语言，方便代码高亮。
* `include`：标签页中所要包含的文件。如果标签页是在 Hugo 的
  [叶子包](https://gohugo.io/content-management/page-bundles/#leaf-bundles)中定义，
  Hugo 会在包内查找文件（可以是 Hugo 所支持的任何 MIME 类型文件）。
  否则，Hugo 会在当前路径的相对路径下查找所要包含的内容页面。
  注意，在 `include` 页面中不能包含短代码内容，必须要使用自结束（self-closing）语法。
  例如 `{{< tab name="Content File #1" include="example1" />}}`。
  如果没有在 `codelang` 进行声明的话，Hugo 会根据文件名推测所用的语言。
  默认情况下，非内容文件将会被代码高亮。
<!--
* If your inner content is markdown, you must use the `%`-delimiter to surround the tab.
  For example, `{{% tab name="Tab 1" %}}This is **markdown**{{% /tab %}}`
* You can combine the variations mentioned above inside a tab set.
-->
* 如果内部内容是 Markdown，你必须要使用 `%` 分隔符来包装标签页。
  例如，`{{% tab name="Tab 1" %}}This is **markdown**{{% /tab %}}`。
* 可以在标签页集中混合使用上面的各种变形。

<!--
Below is a demo of the tabs shortcode.
-->
下面是标签页短代码的示例。


<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
The tab **name** in a `tabs` definition must be unique within a content page.
-->
<p>内容页面下的 <strong>tabs</strong> 定义中的标签页 <strong>name</strong> 必须是唯一的。</p></div>


<!--
### Tabs demo: Code highlighting
-->
### 标签页演示：代码高亮

```go-text-template
{{< tabs name="tab_with_code" >}}
{{< tab name="Tab 1" codelang="bash" >}}
echo "This is tab 1."
{{< /tab >}}
{{< tab codelang="go" >}}
println "This is tab 2."
{{< /tab >}}
{{< /tabs >}}
```

<!--
Renders to:
-->
会转换为：

<!--
If you don't set a tab name, the site supplies one.
-->
<ul class="nav nav-tabs" id="tabs-tab-with-code" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-tab-with-code-0" role="tab" aria-controls="tabs-tab-with-code-0" aria-selected="true">Tab A</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-tab-with-code-1" role="tab" aria-controls="tabs-tab-with-code-1">Tab 2</a></li></ul>

<div class="tab-content" id="tabs-tab-with-code-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-tab-with-code-0" role="tabpanel" aria-labelledby="tabs-tab-with-code-0-tab" tabindex="tab-with-code"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;This is tab A.&#34;</span>
</span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-tab-with-code-1" role="tabpanel" aria-labelledby="tabs-tab-with-code-1-tab" tabindex="tab-with-code"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c1">// 如果你未设置标签名，则网站提供一个名称。</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nx">println</span><span class="w"> </span><span class="s">&#34;This tab has a default name&#34;</span><span class="p">;</span><span class="w">
</span></span></span></code></pre></div></div></div>


<!--
### Tabs demo: Inline Markdown and HTML
-->
### 标签页演示：内联 Markdown 和 HTML

<!--
```go-html-template
{{< tabs name="tab_with_md" >}}
{{% tab name="Markdown" %}}
This is **some markdown.**
{{< note >}}
It can even contain shortcodes.
{{< /note >}}
{{% /tab %}}
{{< tab name="HTML" >}}
<div>
	<h3>Plain HTML</h3>
	<p>This is some <i>plain</i> HTML.</p>
</div>
{{< /tab >}}
{{< /tabs >}}
```
-->
```go-html-template
{{< tabs name="tab_with_md" >}}
{{% tab name="Markdown" %}}
这是**一些 markdown。**
{{< note >}}
它甚至可以包含短代码。
{{< /note >}}
{{% /tab %}}
{{< tab name="HTML" >}}
<div>
	<h3>纯 HTML</h3>
	<p>这是一些 <i>纯</i> HTML。</p>
</div>
{{< /tab >}}
{{< /tabs >}}
```

<!--
Renders to:
-->
会转换为：

<ul class="nav nav-tabs" id="tabs-tab-with-md" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-tab-with-md-0" role="tab" aria-controls="tabs-tab-with-md-0" aria-selected="true">Markdown</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-tab-with-md-1" role="tab" aria-controls="tabs-tab-with-md-1">HTML</a></li></ul>

<div class="tab-content" id="tabs-tab-with-md-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-tab-with-md-0" role="tabpanel" aria-labelledby="tabs-tab-with-md-0-tab" tabindex="tab-with-md"><!--
This is **some markdown.**
-->
<p>这是<strong>一些 markdown。</strong></p>
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
It can even contain shortcodes.
-->
<p>它甚至可以包含短代码。</p></div>
</div><div class="tab-body tab-pane fade"
        id="tabs-tab-with-md-1" role="tabpanel" aria-labelledby="tabs-tab-with-md-1-tab" tabindex="tab-with-md">
<div>
	<h3>
  <!--
  Plain HTML
  -->
  纯 HTML
  </h3>
	<p>
  <!--
  This is some <i>plain</i> HTML.
  -->
  这是一些 <i>纯</i> HTML。
  </p>
</div>
</div></div>


<!--
### Tabs demo: File include
-->
### 标签页演示：文件嵌套

```go-text-template
{{< tabs name="tab_with_file_include" >}}
{{< tab name="Content File #1" include="example1" />}}
{{< tab name="Content File #2" include="example2" />}}
{{< tab name="JSON File" include="podtemplate" />}}
{{< /tabs >}}
```

<!--
Renders to:
-->
会转换为：

<ul class="nav nav-tabs" id="tabs-tab-with-file-include" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-tab-with-file-include-0" role="tab" aria-controls="tabs-tab-with-file-include-0" aria-selected="true">Content File #1</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-tab-with-file-include-1" role="tab" aria-controls="tabs-tab-with-file-include-1">Content File #2</a></li>
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-tab-with-file-include-2" role="tab" aria-controls="tabs-tab-with-file-include-2">JSON File</a></li></ul>

<div class="tab-content" id="tabs-tab-with-file-include-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-tab-with-file-include-0" role="tabpanel" aria-labelledby="tabs-tab-with-file-include-0-tab" tabindex="tab-with-file-include"><!--
title: Example #1
-->
<!--
This is an **example** content file inside the **includes** leaf bundle.
-->
<p>这是一个内容文件<strong>示例</strong>，位于一个<strong>includes</strong>叶子包中。</p>
<!--
Included content files can also contain shortcodes.
-->

<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4>被包含的内容文件也可以包含短代码。</div>

</div><div class="tab-body tab-pane fade"
        id="tabs-tab-with-file-include-1" role="tabpanel" aria-labelledby="tabs-tab-with-file-include-1-tab" tabindex="tab-with-file-include"><!--
title: Example #1
-->
<!--
This is another **example** content file inside the **includes** leaf bundle.
-->
<p>这是另一个内容文件<strong>示例</strong>，位于一个<strong>includes</strong>叶子包中。</p>
</div><div class="tab-body tab-pane fade"
        id="tabs-tab-with-file-include-2" role="tabpanel" aria-labelledby="tabs-tab-with-file-include-2-tab" tabindex="tab-with-file-include"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl">  <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;apiVersion&#34;</span><span class="p">:</span> <span class="s2">&#34;v1&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;kind&#34;</span><span class="p">:</span> <span class="s2">&#34;PodTemplate&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;metadata&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;name&#34;</span><span class="p">:</span> <span class="s2">&#34;nginx&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;template&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;metadata&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nt">&#34;labels&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">          <span class="nt">&#34;name&#34;</span><span class="p">:</span> <span class="s2">&#34;nginx&#34;</span>
</span></span><span class="line"><span class="cl">        <span class="p">},</span>
</span></span><span class="line"><span class="cl">        <span class="nt">&#34;generateName&#34;</span><span class="p">:</span> <span class="s2">&#34;nginx-&#34;</span>
</span></span><span class="line"><span class="cl">      <span class="p">},</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;spec&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">         <span class="nt">&#34;containers&#34;</span><span class="p">:</span> <span class="p">[{</span>
</span></span><span class="line"><span class="cl">           <span class="nt">&#34;name&#34;</span><span class="p">:</span> <span class="s2">&#34;nginx&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">           <span class="nt">&#34;image&#34;</span><span class="p">:</span> <span class="s2">&#34;dockerfile/nginx&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">           <span class="nt">&#34;ports&#34;</span><span class="p">:</span> <span class="p">[{</span><span class="nt">&#34;containerPort&#34;</span><span class="p">:</span> <span class="mi">80</span><span class="p">}]</span>
</span></span><span class="line"><span class="cl">         <span class="p">}]</span>
</span></span><span class="line"><span class="cl">      <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span>
</span></span></code></pre></div></div></div>


<!--
## Source code files

You can use the `{{% code_sample %}}` shortcode to embed the contents of file in a code block to allow users to download or copy its content to their clipboard. This shortcode is used when the contents of the sample file is generic and reusable, and you want the users to try it out themselves.
-->
## 源代码文件 {#source-code-files}

你可以使用 `{{% code_sample %}}` 短代码将文件内容嵌入代码块中，
以允许用户下载或复制其内容到他们的剪贴板。
当示例文件的内容是通用的、可复用的，并且希望用户自己尝试使用示例文件时，
可以使用此短代码。

<!--
This shortcode takes in two named parameters: `language` and `file`. The mandatory parameter `file` is used to specify the path to the file being displayed. The optional parameter `language` is used to specify the programming language of the file. If the `language` parameter is not provided, the shortcode will attempt to guess the language based on the file extension.

For example:
-->
这个短代码有两个命名参数：`language` 和 `file`，
必选参数 `file` 用于指定要显示的文件的路径，
可选参数 `language` 用于指定文件的编程语言。
如果未提供 `language` 参数，短代码将尝试根据文件扩展名推测编程语言。

例如：

```none
{{% code_sample language="yaml" file="application/deployment-scale.yaml" %}}
```

<!--
The output is:
-->
输出是：


















<div class="highlight code-sample">
    <div class="copy-code-icon">
    <a href="https://raw.githubusercontent.com/kubernetes/website/main/content/zh-cn/examples/application/deployment-scale.yaml" download="application/deployment-scale.yaml"><code>application/deployment-scale.yaml</code>
    </a><img src="/images/copycode.svg" class="icon-copycode" onclick="copyCode('application-deployment-scale-yaml')" title="复制 application/deployment-scale.yaml 到剪贴板"></img></div>
    <div class="includecode" id="application-deployment-scale-yaml"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">apiVersion</span><span class="p">:</span><span class="w"> </span><span class="l">apps/v1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">kind</span><span class="p">:</span><span class="w"> </span><span class="l">Deployment</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">metadata</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">nginx-deployment</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">spec</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">selector</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">matchLabels</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">app</span><span class="p">:</span><span class="w"> </span><span class="l">nginx</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">replicas</span><span class="p">:</span><span class="w"> </span><span class="m">4</span><span class="w"> </span><span class="c"># 将副本数从 2 更新为 4</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">template</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">metadata</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">labels</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">app</span><span class="p">:</span><span class="w"> </span><span class="l">nginx</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">spec</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">containers</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">nginx</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">nginx:1.16.1</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">ports</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span>- <span class="nt">containerPort</span><span class="p">:</span><span class="w"> </span><span class="m">80</span><span class="w">
</span></span></span></code></pre></div></div>
</div>

<!--
When adding a new sample file, such as a YAML file, create the file in one of the `<LANG>/examples/` subdirectories where `<LANG>` is the language for the page. In the markdown of your page, use the `code` shortcode:
-->
添加新的示例文件（例如 YAML 文件）时，在 `<LANG>/examples/`
子目录之一中创建该文件，其中 `<LANG>` 是页面的语言。
在你的页面的 Markdown 文本中，使用 `code` 短代码：

```none
{{% code_sample file="<RELATIVE-PATH>/example-yaml>" %}}
```

<!--
where `<RELATIVE-PATH>` is the path to the sample file to include, relative to the `examples` directory. The following shortcode references a YAML file located at `/content/en/examples/configmap/configmaps.yaml`.
-->
其中 `<RELATIVE-PATH>` 是要包含的示例文件的路径，相对于 `examples` 目录。
以下短代码引用位于 `/content/en/examples/configmap/configmaps.yaml` 的 YAML 文件。

```none
{{% code_sample file="configmap/configmaps.yaml" %}}
```

<!--
The legacy `{{% codenew %}}` shortcode is being replaced by `{{% code_sample %}}`.
Use `{{% code_sample %}}` (not `{{% codenew %}}` or `{{% code %}}`) in new documentation.
-->
传统的 `{{% codenew %}}` 短代码将被替换为 `{{% code_sample %}}`。
在新文档中使用 `{{% code_sample %}}`。

<!--
## Third party content marker
-->
## 第三方内容标记  {#third-party-content-marker}

<!--
Running Kubernetes requires third-party software. For example: you
usually need to add a
[DNS server](/docs/tasks/administer-cluster/dns-custom-nameservers/#introduction)
to your cluster so that name resolution works.
-->
运行 Kubernetes 需要第三方软件。例如：你通常需要将
[DNS 服务器](/zh-cn/docs/tasks/administer-cluster/dns-custom-nameservers/#introduction)添加到集群中，
以便名称解析工作。

<!--
When we link to third-party software, or otherwise mention it,
we follow the [content guide](/docs/contribute/style/content-guide/)
and we also mark those third party items.
-->
当我们链接到第三方软件或以其他方式提及它时，
我们会遵循[内容指南](/zh-cn/docs/contribute/style/content-guide/)并标记这些第三方项目。

<!--
Using these shortcodes adds a disclaimer to any documentation page
that uses them.
-->
使用这些短代码会向使用它们的任何文档页面添加免责声明。

<!--
### Lists {#third-party-content-list}
-->
### 列表  {#third-party-content-list}

<!--
For a list of several third-party items, add:
-->
对于有关几个第三方项目的列表，请添加：

```
{{% thirdparty-content %}}
```

<!--
just below the heading for the section that includes all items.
-->
在包含所有项目的段落标题正下方。

<!--
### Items {#third-party-content-item}
-->
### 项目  {#third-party-content-item}

<!--
If you have a list where most of the items refer to in-project
software (for example: Kubernetes itself, and the separate
[Descheduler](https://github.com/kubernetes-sigs/descheduler)
component), then there is a different form to use.
-->
如果你有一个列表，其中大多数项目引用项目内软件（例如：Kubernetes 本身，以及单独的
[Descheduler](https://github.com/kubernetes-sigs/descheduler)
组件），那么可以使用不同的形式。

<!--
Add the shortcode:
-->
添加短代码：

```
{{% thirdparty-content single="true" %}}
```

<!--
before the item, or just below the heading for the specific item.
-->
在项目之前，或在特定项目的段落下方添加此短代码。

<!--
## Details

You can render a `<details>` HTML element using a shortcode:
-->
## 详细信息 {#details}

你可以使用短代码呈现 `<details>` HTML 元素：

<!--
```markdown
{{< details summary="More about widgets" >}}
The frobnicator extension API implements _widgets_ using example running text.

Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et
dolore magnam aliquam quaerat voluptatem.
{{< /details >}}
```
-->
```markdown
{{< details summary="有关 widgets 的更多信息" >}}
frobnicator 扩展 API 使用示例运行文本实现 **widgets**。

没有哪个人会因为痛苦本身就是令人愉悦的，而选择痛苦，
尽管他们有时因为追求某种快乐而不得不承受痛苦。
但这并不是说他们喜欢痛苦本身，而是因为通过忍受痛苦，他们可以得到更大的快乐。
{{< /details >}}
```

<!--
This renders as:
-->
渲染结果如下：

<!--
<details><summary>More about widgets</summary><div class="details-inner">
    <p>The frobnicator extension API implements <em>widgets</em> using example running text.</p>
<p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et
dolore magnam aliquam quaerat voluptatem.</p>

  </div>
</details>

-->
<details><summary>有关 widgets 的更多信息</summary><div class="details-inner">
    <p>frobnicator 扩展 API 使用示例运行文本实现 <strong>widgets</strong>。</p>
<p>没有哪个人会因为痛苦本身就是令人愉悦的，而选择痛苦，
尽管他们有时因为追求某种快乐而不得不承受痛苦。
但这并不是说他们喜欢痛苦本身，而是因为通过忍受痛苦，他们可以得到更大的快乐。</p>

  </div>
</details>



<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
Use this shortcode sparingly; it is usually best to have all of the text directly shown
to readers.
-->
<p>谨慎使用此短代码；通常最好将所有文本直接显示给读者。</p></div>


<!--
## Version strings

To generate a version string for inclusion in the documentation, you can choose from
several version shortcodes. Each version shortcode displays a version string derived from
the value of a version parameter found in the site configuration file, `hugo.toml`.
The two most commonly used version parameters are `latest` and `version`.
-->
## 版本号信息 {#version-strings}

要在文档中生成版本号信息，可以从以下几种短代码中选择。每个短代码可以基于站点配置文件
`hugo.toml` 中的版本参数生成一个版本号取值。最常用的参数为 `latest` 和 `version`。

<!--
### `{{< param "version" >}}`

The `{{< param "version" >}}` shortcode generates the value of the current
version of the Kubernetes documentation from the `version` site parameter. The
`param` shortcode accepts the name of one site parameter, in this case:
`version`.
-->
### `{{< param "version" >}}`

`{{< param "version" >}}` 短代码可以基于站点参数 `version` 生成 Kubernetes
文档的当前版本号取值。短代码 `param` 允许传入一个站点参数名称，在这里是 `version`。


<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
In previously released documentation, `latest` and `version` parameter values
are not equivalent.  After a new version is released, `latest` is incremented
and the value of `version` for the documentation set remains unchanged. For
example, a previously released version of the documentation displays `version`
as `v1.19` and `latest` as `v1.20`.
-->
<p>在先前已经发布的文档中，<code>latest</code> 和 <code>version</code> 参数值并不完全等价。新版本文档发布后，参数
<code>latest</code> 会增加，而 <code>version</code> 则保持不变。例如，在上一版本的文档中使用 <code>version</code> 会得到
<code>v1.19</code>，而使用 <code>latest</code> 则会得到 <code>v1.20</code>。</p></div>


<!--
Renders to:
-->
转换为：

v1.36

<!--
### `{{< latest-version >}}`

The `{{< latest-version >}}` shortcode returns the value of the `latest` site parameter.
The `latest` site parameter is updated when a new version of the documentation is released.
This parameter does not always match the value of `version` in a documentation set.

Renders to:
-->
### `{{< latest-version >}}`

`{{< latest-version >}}` 返回站点参数 `latest` 的取值。每当新版本文档发布时，该参数均会被更新。
因此，参数 `latest` 与 `version` 并不总是相同。

转换为：

v1.36

<!--
### `{{< latest-semver >}}`

The `{{< latest-semver >}}` shortcode generates the value of `latest`
without the "v" prefix.

Renders to:
-->
### `{{< latest-semver >}}`

`{{< latest-semver >}}` 短代码可以生成站点参数 `latest` 不含前缀
`v` 的版本号取值。

转换为：

1.36

<!--
### `{{< version-check >}}`

The `{{< version-check >}}` shortcode checks if the `min-kubernetes-server-version`
page parameter is present and then uses this value to compare to `version`.

Renders to:
-->
### `{{< version-check >}}`

`{{< version-check >}}` 会检查是否设置了页面参数 `min-kubernetes-server-version`
并将其与 `version` 进行比较。

转换为：


 <p>要获知版本信息，请输入  <code>kubectl version</code>.</p>


<!--
### `{{< latest-release-notes >}}`

The `{{< latest-release-notes >}}` shortcode generates a version string
from `latest` and removes the "v" prefix. The shortcode prints a new URL for
the release note CHANGELOG page with the modified version string.

Renders to:
-->
### `{{< latest-release-notes >}}`

`{{< latest-release-notes >}}` 短代码基于站点参数 `latest` 生成不含前缀 `v`
的版本号取值，并输出该版本更新日志的超链接地址。

转换为：

https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.36.md


## 接下来

<!--
* Learn about [Hugo](https://gohugo.io/).
* Learn about [writing a new topic](/docs/contribute/style/write-new-topic/).
* Learn about [page content types](/docs/contribute/style/page-content-types/).
* Learn about [opening a pull request](/docs/contribute/new-content/open-a-pr/).
* Learn about [advanced contributing](/docs/contribute/advanced/).
-->
* 了解 [Hugo](https://gohugo.io/)。
* 了解[撰写新的话题](/zh-cn/docs/contribute/style/write-new-topic/)。
* 了解[使用页面内容类型](/zh-cn/docs/contribute/style/page-content-types/)。
* 了解[发起 PR](/zh-cn/docs/contribute/new-content/open-a-pr/)。
* 了解[进阶贡献](/zh-cn/docs/contribute/advanced/)。
