Skip to content

Commit e3d0384

Browse files
authored
Merge pull request #31175 from tengqm/zh-hostprocess
[zh] Translate create hostprocess pod
2 parents 7e268d8 + 7bc2709 commit e3d0384

File tree

1 file changed

+345
-0
lines changed

1 file changed

+345
-0
lines changed
Lines changed: 345 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
---
2+
title: 创建 Windows HostProcess Pod
3+
content_type: task
4+
weight: 20
5+
min-kubernetes-server-version: 1.23
6+
---
7+
8+
<!--
9+
title: Create a Windows HostProcess Pod
10+
content_type: task
11+
weight: 20
12+
min-kubernetes-server-version: 1.23
13+
-->
14+
15+
<!-- overview -->
16+
17+
{{< feature-state for_k8s_version="v1.23" state="beta" >}}
18+
19+
<!--
20+
Windows HostProcess containers enable you to run containerized
21+
workloads on a Windows host. These containers operate as
22+
normal processes but have access to the host network namespace,
23+
storage, and devices when given the appropriate user privileges.
24+
HostProcess containers can be used to deploy network plugins,
25+
storage configurations, device plugins, kube-proxy, and other
26+
components to Windows nodes without the need for dedicated proxies or
27+
the direct installation of host services.
28+
-->
29+
Windows HostProcess 容器让你能够在 Windows 主机上运行容器化负载。
30+
这类容器以普通的进程形式运行,但能够在具有合适用户特权的情况下,
31+
访问主机网络名字空间、存储和设备。HostProcess 容器可用来在 Windows
32+
节点上部署网络插件、存储配置、设备插件、kube-proxy 以及其他组件,
33+
同时不需要配置专用的代理或者直接安装主机服务。
34+
35+
<!--
36+
Administrative tasks such as installation of security patches, event
37+
log collection, and more can be performed without requiring cluster operators to
38+
log onto each Window node. HostProcess containers can run as any user that is
39+
available on the host or is in the domain of the host machine, allowing administrators
40+
to restrict resource access through user permissions. While neither filesystem or process
41+
isolation are supported, a new volume is created on the host upon starting the container
42+
to give it a clean and consolidated workspace. HostProcess containers can also be built on
43+
top of existing Windows base images and do not inherit the same
44+
[compatibility requirements](https://docs.microsoft.com/virtualization/windowscontainers/deploy-containers/version-compatibility)
45+
as Windows server containers, meaning that the version of the base images does not need
46+
to match that of the host. It is, however, recommended that you use the same base image
47+
version as your Windows Server container workloads to ensure you do not have any unused
48+
images taking up space on the node. HostProcess containers also support
49+
[volume mounts](./create-hostprocess-pod#volume-mounts) within the container volume.
50+
-->
51+
类似于安装安全补丁、事件日志收集等这类管理性质的任务可以在不需要集群操作员登录到每个
52+
Windows 节点的前提下执行。HostProcess 容器可以以主机上存在的任何用户账户来运行,
53+
也可以以主机所在域中的用户账户运行,这样管理员可以通过用户许可权限来限制资源访问。
54+
尽管文件系统和进程隔离都不支持,在启动容器时会在主机上创建一个新的卷,
55+
为其提供一个干净的、整合的工作空间。HostProcess 容器也可以基于现有的 Windows
56+
基础镜像来制作,并且不再有 Windows 服务器容器所带有的那些
57+
[兼容性需求](https://docs.microsoft.com/virtualization/windowscontainers/deploy-containers/version-compatibility)
58+
这意味着基础镜像的版本不必与主机操作系统的版本匹配。
59+
不过,仍然建议你像使用 Windows 服务器容器负载那样,使用相同的基础镜像版本,
60+
这样你就不会有一些未使用的镜像占用节点上的存储空间。HostProcess 容器也支持
61+
在容器卷内执行[卷挂载](./create-hostprocess-pod#volume-mounts)
62+
63+
<!--
64+
### When should I use a Windows HostProcess container?
65+
66+
- When you need to perform tasks which require the networking namespace of the host.
67+
HostProcess containers have access to the host's network interfaces and IP addresses.
68+
- You need access to resources on the host such as the filesystem, event logs, etc.
69+
- Installation of specific device drivers or Windows services.
70+
- Consolidation of administrative tasks and security policies. This reduces the degree of
71+
privileges needed by Windows nodes.
72+
-->
73+
### 我何时该使用 Windows HostProcess 容器?
74+
75+
- 当你准备执行需要访问主机上网络名字空间的任务时,HostProcess
76+
容器能够访问主机上的网络接口和 IP 地址。
77+
- 当你需要访问主机上的资源,如文件系统、事件日志等等。
78+
- 需要安装特定的设备驱动或者 Windows 服务时。
79+
- 需要对管理任务和安全策略进行整合时。使用 HostProcess 容器能够缩小 Windows
80+
节点上所需要的特权范围。
81+
82+
## {{% heading "prerequisites" %}}
83+
84+
<!-- change this when graduating to stable -->
85+
86+
<!--
87+
This task guide is specific to Kubernetes v{{< skew currentVersion >}}.
88+
If you are not running Kubernetes v{{< skew currentVersion >}}, check the documentation for
89+
that version of Kubernetes.
90+
91+
In Kubernetes {{< skew currentVersion >}}, the HostProcess container feature is enabled by default. The kubelet will
92+
communicate with containerd directly by passing the hostprocess flag via CRI. You can use the
93+
latest version of containerd (v1.6+) to run HostProcess containers.
94+
[How to install containerd.](/docs/setup/production-environment/container-runtimes/#containerd)
95+
-->
96+
本任务指南是特定于 Kubernetes v{{< skew currentVersion >}} 的。
97+
如果你运行的不是 Kubernetes v{{< skew currentVersion >}},请移步访问正确
98+
版本的 Kubernetes 文档。
99+
100+
在 Kubernetes v{{< skew currentVersion >}} 中,HostProcess 容器功能特性默认是启用的。
101+
kubelet 会直接与 containerd 通信,通过 CRI 将主机进程标志传递过去。
102+
你可以使用 containerd 的最新版本(v1.6+)来运行 HostProcess 容器。
103+
参阅[如何安装 containerd](/zh/docs/setup/production-environment/container-runtimes/#containerd)
104+
105+
<!--
106+
To *disable* HostProcess containers you need to pass the following feature gate flag to the
107+
**kubelet** and **kube-apiserver**:
108+
-->
109+
*禁用* HostProcess 容器特性,你需要为 **kubelet****kube-apiserver**
110+
设置下面的特性门控标志:
111+
112+
```powershell
113+
--feature-gates=WindowsHostProcessContainers=false
114+
```
115+
116+
<!--
117+
See [Features Gates](/docs/reference/command-line-tools-reference/feature-gates/#overview)
118+
documentation for more details.
119+
-->
120+
进一步的细节可参阅[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/#overview)文档。
121+
122+
<!--
123+
## Limitations
124+
125+
These limitations are relevant for Kubernetes v{{< skew currentVersion >}}:
126+
-->
127+
## 限制 {#limitations}
128+
129+
以下限制是与 Kubernetes v{{< skew currentVersion >}} 相关的:
130+
131+
<!--
132+
- HostProcess containers require containerd 1.6 or higher
133+
{{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}.
134+
- HostProcess pods can only contain HostProcess containers. This is a current limitation
135+
of the Windows OS; non-privileged Windows containers cannot share a vNIC with the host IP namespace.
136+
- HostProcess containers run as a process on the host and do not have any degree of
137+
isolation other than resource constraints imposed on the HostProcess user account. Neither
138+
filesystem or Hyper-V isolation are supported for HostProcess containers.
139+
-->
140+
- HostProcess 容器需要 containerd 1.6 或更高版本的
141+
{{< glossary_tooltip text="容器运行时" term_id="container-runtime" >}}。
142+
- HostProcess Pods 只能包含 HostProcess 容器。这是在 Windows 操作系统上的约束;
143+
非特权的 Windows 容器不能与主机 IP 名字空间共享虚拟网卡(vNIC)。
144+
- HostProcess 在主机上以一个进程的形式运行,除了通过 HostProcess
145+
用户账号所实施的资源约束外,不提供任何形式的隔离。HostProcess 容器不支持文件系统或
146+
Hyper-V 隔离。
147+
<!--
148+
- Volume mounts are supported and are mounted under the container volume. See [Volume Mounts](#volume-mounts)
149+
- A limited set of host user accounts are available for HostProcess containers by default.
150+
See [Choosing a User Account](#choosing-a-user-account).
151+
- Resource limits (disk, memory, cpu count) are supported in the same fashion as processes
152+
on the host.
153+
- Both Named pipe mounts and Unix domain sockets are **not** supported and should instead
154+
be accessed via their path on the host (e.g. \\\\.\\pipe\\\*)
155+
-->
156+
- 卷挂载是被支持的,并且要花在到容器卷下。参见[卷挂载](#volume-mounts)
157+
- 默认情况下有一组主机用户账户可供 HostProcess 容器使用。
158+
参见[选择用户账号](#choosing-a-user-account)
159+
- 对资源约束(磁盘、内存、CPU 个数)的支持与主机上进程相同。
160+
- **不支持**命名管道或者 UNIX 域套接字形式的挂载,需要使用主机上的路径名来访问
161+
(例如,\\\\.\\pipe\\\*)。
162+
163+
<!--
164+
## HostProcess Pod configuration requirements
165+
-->
166+
## HostProcess Pod 配置需求 {#hostprocess-pod-configuration-requirements}
167+
168+
<!--
169+
Enabling a Windows HostProcess pod requires setting the right configurations in the pod security
170+
configuration. Of the policies defined in the [Pod Security Standards](/docs/concepts/security/pod-security-standards)
171+
HostProcess pods are disallowed by the baseline and restricted policies. It is therefore recommended
172+
that HostProcess pods run in alignment with the privileged profile.
173+
174+
When running under the privileged policy, here are
175+
the configurations which need to be set to enable the creation of a HostProcess pod:
176+
-->
177+
启用 Windows HostProcess Pod 需要在 Pod 安全配置中设置合适的选项。
178+
[Pod
179+
安全标准](/zh/docs/concepts/security/pod-security-standards)中所定义的策略中,
180+
HostProcess Pod 默认是不被 basline 和 restricted 策略支持的。因此建议
181+
HostProcess 运行在与 privileged 模式相看齐的策略下。
182+
183+
当运行在 privileged 策略下时,下面是要启用 HostProcess Pod 创建所需要设置的选项:
184+
185+
<table>
186+
<caption style="display: none"><!--Privileged policy specification-->privileged 策略规约</caption>
187+
<thead>
188+
<tr>
189+
<th><!--Control-->控制</th>
190+
<th><!--Policy-->策略</th>
191+
</tr>
192+
</thead>
193+
<tbody>
194+
<tr>
195+
<td style="white-space: nowrap"><a href="/zh/docs/concepts/security/pod-security-standards"><tt>securityContext.windowsOptions.hostProcess</tt></a></td>
196+
<td>
197+
<p><!--Windows pods offer the ability to run <a href="/docs/tasks/configure-pod-container/create-hostprocess-pod">
198+
HostProcess containers</a> which enables privileged access to the Windows node.-->
199+
Windows Pods 提供运行<a href="/zh/docs/tasks/configure-pod-container/create-hostprocess-pod">
200+
HostProcess 容器</a>的能力,这类容器能够具有对 Windows 节点的特权访问权限。</p>
201+
<p><strong><!--Allowed Values-->可选值</strong></p>
202+
<ul>
203+
<li><code>true</code></li>
204+
</ul>
205+
</td>
206+
</tr>
207+
<tr>
208+
<td style="white-space: nowrap"><a href="/zh/docs/concepts/security/pod-security-standards"><tt>hostNetwork</tt></a></td>
209+
<td>
210+
<p><!--Will be in host network by default initially. Support
211+
to set network to a different compartment may be desirable in
212+
the future.-->
213+
初始时将默认位于主机网络中。在未来可能会希望将网络设置到不同的隔离环境中。
214+
</p>
215+
<p><strong><!--Allowed Values-->可选值</strong></p>
216+
<ul>
217+
<li><code>true</code></li>
218+
</ul>
219+
</td>
220+
</tr>
221+
<tr>
222+
<td style="white-space: nowrap"><a href="/zh/docs/tasks/configure-pod-container/configure-runasusername/"><tt>securityContext.windowsOptions.runAsUsername</tt></a></td>
223+
<td>
224+
<p><!--Specification of which user the HostProcess container should run as is required for the pod spec.-->
225+
关于 HostProcess 容器所要使用的用户的规约,需要设置在 Pod 的规约中。
226+
</p>
227+
<p><strong><!--Allowed Values-->可选值</strong></p>
228+
<ul>
229+
<li><code>NT AUTHORITY\SYSTEM</code></li>
230+
<li><code>NT AUTHORITY\Local service</code></li>
231+
<li><code>NT AUTHORITY\NetworkService</code></li>
232+
</ul>
233+
</td>
234+
</tr>
235+
<tr>
236+
<td style="white-space: nowrap"><a href="/zh/docs/concepts/security/pod-security-standards"><tt>runAsNonRoot</tt></a></td>
237+
<td>
238+
<p><!--Because HostProcess containers have privileged access to the host, the <tt>runAsNonRoot</tt> field cannot be set to true.-->
239+
因为 HostProcess 容器有访问主机的特权,<tt>runAsNonRoot</tt> 字段不可以设置为 true。
240+
</p>
241+
<p><strong><!--Allowed Values-->可选值</strong></p>
242+
<ul>
243+
<li><!--Undefined/Nil-->未定义/Nil</li>
244+
<li><code>false</code></li>
245+
</ul>
246+
</td>
247+
</tr>
248+
</tbody>
249+
</table>
250+
251+
<!--
252+
### Example manifest (excerpt) {#manifest-example}
253+
-->
254+
### 配置清单示例(片段) {#manifest-example}
255+
256+
```yaml
257+
spec:
258+
securityContext:
259+
windowsOptions:
260+
hostProcess: true
261+
runAsUserName: "NT AUTHORITY\\Local service"
262+
hostNetwork: true
263+
containers:
264+
- name: test
265+
image: image1:latest
266+
command:
267+
- ping
268+
- -t
269+
- 127.0.0.1
270+
nodeSelector:
271+
"kubernetes.io/os": windows
272+
```
273+
274+
<!--
275+
## Volume mounts
276+
277+
HostProcess containers support the ability to mount volumes within the container volume space.
278+
Applications running inside the container can access volume mounts directly via relative or
279+
absolute paths. An environment variable `$CONTAINER_SANDBOX_MOUNT_POINT` is set upon container
280+
creation and provides the absolute host path to the container volume. Relative paths are based
281+
upon the `.spec.containers.volumeMounts.mountPath` configuration.
282+
-->
283+
## 卷挂载 {#volume-mounts}
284+
285+
HostProcess 容器支持在容器卷空间中挂载卷的能力。
286+
在容器内运行的应用能够通过相对或者绝对路径直接访问卷挂载。
287+
环境变量 `$CONTAINER_SANDBOX_MOUNT_POINT` 在容器创建时被设置为指向容器卷的绝对主机路径。
288+
相对路径是基于 `.spec.containers.volumeMounts.mountPath` 配置来推导的。
289+
290+
<!--
291+
### Example {#volume-mount-example}
292+
293+
To access service account tokens the following path structures are supported within the container:
294+
-->
295+
### 示例 {#volume-mount-example}
296+
297+
容器内支持通过下面的路径结构来访问服务账好令牌:
298+
299+
`.\var\run\secrets\kubernetes.io\serviceaccount\`
300+
301+
`$CONTAINER_SANDBOX_MOUNT_POINT\var\run\secrets\kubernetes.io\serviceaccount\`
302+
303+
<!--
304+
## Resource limits
305+
306+
Resource limits (disk, memory, cpu count) are applied to the job and are job wide.
307+
For example, with a limit of 10MB set, the memory allocated for any HostProcess job object
308+
will be capped at 10MB. This is the same behavior as other Windows container types.
309+
These limits would be specified the same way they are currently for whatever orchestrator
310+
or runtime is being used. The only difference is in the disk resource usage calculation
311+
used for resource tracking due to the difference in how HostProcess containers are bootstrapped.
312+
-->
313+
## 资源约束 {#resource-limits}
314+
315+
资源约束(磁盘、内存、CPU 个数)作用到任务之上,并在整个任务上起作用。
316+
例如,如果内存限制设置为 10MB,任何 HostProcess 任务对象所分配的内存不会超过 10MB。
317+
这一行为与其他 Windows 容器类型相同。资源限制的设置方式与编排系统或容器运行时无关。
318+
唯一的区别是用来跟踪资源所进行的磁盘资源用量的计算,出现差异的原因是因为
319+
HostProcess 容器启动引导的方式造成的。
320+
321+
<!--
322+
## Choosing a user account
323+
324+
HostProcess containers support the ability to run as one of three supported Windows service accounts:
325+
-->
326+
## 选择用户账号 {#choosing-a-user-account}
327+
328+
HostProcess 容器支持以三种被支持的 Windows 服务账号之一来运行:
329+
330+
- **[LocalSystem](https://docs.microsoft.com/windows/win32/services/localsystem-account)**
331+
- **[LocalService](https://docs.microsoft.com/windows/win32/services/localservice-account)**
332+
- **[NetworkService](https://docs.microsoft.com/windows/win32/services/networkservice-account)**
333+
334+
<!--
335+
You should select an appropriate Windows service account for each HostProcess
336+
container, aiming to limit the degree of privileges so as to avoid accidental (or even
337+
malicious) damage to the host. The LocalSystem service account has the highest level
338+
of privilege of the three and should be used only if absolutely necessary. Where possible,
339+
use the LocalService service account as it is the least privileged of the three options.
340+
-->
341+
你应该为每个 HostProcess 容器选择一个合适的 Windows 服务账号,尝试限制特权范围,
342+
避免给主机代理意外的(甚至是恶意的)伤害。LocalSystem 服务账号的特权级
343+
在三者之中最高,只有在绝对需要的时候才应该使用。只要可能,应该使用
344+
LocalService 服务账号,因为该账号在三者中特权最低。
345+

0 commit comments

Comments
 (0)