1
1
---
2
2
title : 创建 Windows HostProcess Pod
3
3
content_type : task
4
- weight : 20
4
+ weight : 50
5
5
min-kubernetes-server-version : 1.23
6
6
---
7
-
8
7
<!--
9
8
title: Create a Windows HostProcess Pod
10
9
content_type: task
11
- weight: 20
10
+ weight: 50
12
11
min-kubernetes-server-version: 1.23
13
12
-->
14
13
15
14
<!-- overview -->
16
15
17
- {{< feature-state for_k8s_version="v1.23 " state="beta " >}}
16
+ {{< feature-state for_k8s_version="v1.26 " state="stable " >}}
18
17
19
18
<!--
20
19
Windows HostProcess containers enable you to run containerized
@@ -49,8 +48,8 @@ images taking up space on the node. HostProcess containers also support
49
48
[volume mounts](#volume-mounts) within the container volume.
50
49
-->
51
50
类似于安装安全补丁、事件日志收集等这类管理性质的任务可以在不需要集群操作员登录到每个
52
- Windows 节点的前提下执行。HostProcess 容器可以以主机上存在的任何用户账户来运行 ,
53
- 也可以以主机所在域中的用户账户运行 ,这样管理员可以通过用户许可权限来限制资源访问。
51
+ Windows 节点的前提下执行。HostProcess 容器可以以主机上存在的任何用户账号来运行 ,
52
+ 也可以以主机所在域中的用户账号运行 ,这样管理员可以通过用户许可权限来限制资源访问。
54
53
尽管文件系统和进程隔离都不支持,在启动容器时会在主机上创建一个新的卷,
55
54
为其提供一个干净的、整合的工作空间。HostProcess 容器也可以基于现有的 Windows
56
55
基础镜像来制作,并且不再有 Windows 服务器容器所带有的那些
@@ -102,23 +101,6 @@ kubelet 会直接与 containerd 通信,通过 CRI 将主机进程标志传递
102
101
你可以使用 containerd 的最新版本(v1.6+)来运行 HostProcess 容器。
103
102
参阅[ 如何安装 containerd] ( /zh-cn/docs/setup/production-environment/container-runtimes/#containerd ) 。
104
103
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-cn/docs/reference/command-line-tools-reference/feature-gates/#overview ) 文档。
121
-
122
104
<!--
123
105
## Limitations
124
106
@@ -130,17 +112,19 @@ These limitations are relevant for Kubernetes v{{< skew currentVersion >}}:
130
112
131
113
<!--
132
114
- HostProcess containers require containerd 1.6 or higher
133
- {{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}.
115
+ {{< glossary_tooltip text="container runtime" term_id="container-runtime" >}} and
116
+ containerd 1.7 is recommended.
134
117
- HostProcess pods can only contain HostProcess containers. This is a current limitation
135
118
of the Windows OS; non-privileged Windows containers cannot share a vNIC with the host IP namespace.
136
119
- HostProcess containers run as a process on the host and do not have any degree of
137
120
isolation other than resource constraints imposed on the HostProcess user account. Neither
138
121
filesystem or Hyper-V isolation are supported for HostProcess containers.
139
122
-->
140
123
- HostProcess 容器需要 containerd 1.6 或更高版本的
141
- {{< glossary_tooltip text="容器运行时" term_id="container-runtime" >}}。
124
+ {{< glossary_tooltip text="容器运行时" term_id="container-runtime" >}},
125
+ 推荐 containerd 1.7。
142
126
- HostProcess Pods 只能包含 HostProcess 容器。这是在 Windows 操作系统上的约束;
143
- 非特权的 Windows 容器不能与主机 IP 名字空间共享虚拟网卡(vNIC)。
127
+ 非特权的 Windows 容器不能与主机 IP 名字空间共享虚拟网卡(vNIC)。
144
128
- HostProcess 在主机上以一个进程的形式运行,除了通过 HostProcess
145
129
用户账号所实施的资源约束外,不提供任何形式的隔离。HostProcess 容器不支持文件系统或
146
130
Hyper-V 隔离。
@@ -155,7 +139,7 @@ These limitations are relevant for Kubernetes v{{< skew currentVersion >}}:
155
139
be accessed via their path on the host (e.g. \\\\.\\pipe\\\*)
156
140
-->
157
141
- 卷挂载是被支持的,并且要花在到容器卷下。参见[ 卷挂载] ( #volume-mounts ) 。
158
- - 默认情况下有一组主机用户账户可供 HostProcess 容器使用。
142
+ - 默认情况下有一组主机用户账号可供 HostProcess 容器使用。
159
143
参见[ 选择用户账号] ( #choosing-a-user-account ) 。
160
144
- 对资源约束(磁盘、内存、CPU 个数)的支持与主机上进程相同。
161
145
- ** 不支持** 命名管道或者 UNIX 域套接字形式的挂载,需要使用主机上的路径名来访问
@@ -208,10 +192,8 @@ HostProcess 运行在与 privileged 模式相看齐的策略下。
208
192
<tr>
209
193
<td style="white-space: nowrap"><a href="/zh-cn/docs/concepts/security/pod-security-standards"><tt>hostNetwork</tt></a></td>
210
194
<td>
211
- <p><!--Will be in host network by default initially. Support
212
- to set network to a different compartment may be desirable in
213
- the future.-->
214
- 初始时将默认位于主机网络中。在未来可能会希望将网络设置到不同的隔离环境中。
195
+ <p><!--Pods container HostProcess containers must use the host's network namespace.-->
196
+ Pod 容器 HostProcess 容器必须使用主机的网络名字空间。
215
197
</p>
216
198
<p><strong><!--Allowed Values-->可选值</strong></p>
217
199
<ul>
@@ -220,7 +202,7 @@ HostProcess 运行在与 privileged 模式相看齐的策略下。
220
202
</td>
221
203
</tr>
222
204
<tr>
223
- <td style="white-space: nowrap"><a href="/zh-cn/docs/tasks/configure-pod-container/configure-runasusername/"><tt>securityContext.windowsOptions.runAsUsername </tt></a></td>
205
+ <td style="white-space: nowrap"><a href="/zh-cn/docs/tasks/configure-pod-container/configure-runasusername/"><tt>securityContext.windowsOptions.runAsUserName </tt></a></td>
224
206
<td>
225
207
<p><!--Specification of which user the HostProcess container should run as is required for the pod spec.-->
226
208
关于 HostProcess 容器所要使用的用户的规约,需要设置在 Pod 的规约中。
@@ -230,6 +212,10 @@ HostProcess 运行在与 privileged 模式相看齐的策略下。
230
212
<li><code>NT AUTHORITY\SYSTEM</code></li>
231
213
<li><code>NT AUTHORITY\Local service</code></li>
232
214
<li><code>NT AUTHORITY\NetworkService</code></li>
215
+ <li>
216
+ <!-- Local usergroup names (see below) -->
217
+ 本地用户组名称(参见下文)
218
+ </li>
233
219
</ul>
234
220
</td>
235
221
</tr>
@@ -276,30 +262,57 @@ spec:
276
262
## Volume mounts
277
263
278
264
HostProcess containers support the ability to mount volumes within the container volume space.
265
+ Volume mount behavior differs depending on the version of containerd runtime used by on the node.
266
+ -->
267
+ ## 卷挂载 {#volume-mounts}
268
+
269
+ HostProcess 容器支持在容器卷空间中挂载卷的能力。
270
+ 卷挂载行为将因节点所使用的 containerd 运行时版本而异。
271
+
272
+ <!--
273
+ ### Containerd v1.6
274
+
279
275
Applications running inside the container can access volume mounts directly via relative or
280
276
absolute paths. An environment variable ` $CONTAINER_SANDBOX_MOUNT_POINT` is set upon container
281
277
creation and provides the absolute host path to the container volume. Relative paths are based
282
278
upon the `.spec.containers.volumeMounts.mountPath` configuration.
279
+
280
+ To access service account tokens (for example) the following path structures are supported within the container :
283
281
-->
284
- # # 卷挂载 {#volume-mounts}
282
+ # ## containerd v1.6
285
283
286
- HostProcess 容器支持在容器卷空间中挂载卷的能力。
287
284
在容器内运行的应用能够通过相对或者绝对路径直接访问卷挂载。
288
285
环境变量 `$CONTAINER_SANDBOX_MOUNT_POINT` 在容器创建时被设置为指向容器卷的绝对主机路径。
289
286
相对路径是基于 `.spec.containers.volumeMounts.mountPath` 配置来推导的。
290
287
288
+ 容器内支持通过下面的路径结构来访问服务账号令牌:
289
+
290
+ - ` .\v ar\r un\s ecrets\k ubernetes.io\s erviceaccount\`
291
+ - ` $CONTAINER_SANDBOX_MOUNT_POINT\var\run\secrets\kubernetes.io\serviceaccount\`
292
+
291
293
<!--
292
- # ## Example {#volume-mount-example}
294
+ # ## Containerd v1.7 (and greater)
293
295
294
- To access service account tokens the following path structures are supported within the container :
296
+ Applications running inside the container can access volume mounts directly via the volumeMount's
297
+ specified `mountPath` (just like Linux and non-HostProcess Windows containers).
295
298
-->
296
- # ## 示例 {#volume-mount-example }
299
+ # ## containerd v1.7(及更高版本) {#containerd-v1.7-and-greater }
297
300
298
- 容器内支持通过下面的路径结构来访问服务账好令牌:
301
+ 容器内运行的应用可以通过 volumeMount 指定的 `mountPath` 直接访问卷挂载
302
+ (就像 Linux 和非 HostProcess Windows 容器一样)。
299
303
300
- ` .\v ar\r un\s ecrets\k ubernetes.io\s erviceaccount\`
304
+ <!--
305
+ For backwards compatibility volumes can also be accessed via using the same relative paths configured by containerd v1.6.
301
306
302
- ` $CONTAINER_SANDBOX_MOUNT_POINT\var\run\secrets\kubernetes.io\serviceaccount\`
307
+ As an example, to access service account tokens within the container you would use one of the following paths :
308
+ -->
309
+ 为了向后兼容性,卷也可以通过使用由 containerd v1.6 配置的相同相对路径进行访问。
310
+
311
+ 例如,要在容器中访问服务帐户令牌,你将使用以下路径之一:
312
+
313
+ - ` c:\v ar\r un\s ecrets\k ubernetes.io\s erviceaccount`
314
+ - ` /var/run/secrets/kubernetes.io/serviceaccount/`
315
+ - ` $CONTAINER_SANDBOX_MOUNT_POINT\v ar\r un\s ecrets\k ubernetes.io\s erviceaccount\`
303
316
304
317
<!--
305
318
## Resource limits
@@ -311,9 +324,9 @@ These limits would be specified the same way they are currently for whatever orc
311
324
or runtime is being used. The only difference is in the disk resource usage calculation
312
325
used for resource tracking due to the difference in how HostProcess containers are bootstrapped.
313
326
-->
314
- # # 资源约束 {#resource-limits}
327
+ ## 资源限制 {#resource-limits}
315
328
316
- 资源约束 (磁盘、内存、CPU 个数)作用到任务之上,并在整个任务上起作用。
329
+ 资源限制 (磁盘、内存、CPU 个数)作用到任务之上,并在整个任务上起作用。
317
330
例如,如果内存限制设置为 10MB,任何 HostProcess 任务对象所分配的内存不会超过 10MB。
318
331
这一行为与其他 Windows 容器类型相同。资源限制的设置方式与编排系统或容器运行时无关。
319
332
唯一的区别是用来跟踪资源所进行的磁盘资源用量的计算,出现差异的原因是因为
@@ -322,11 +335,15 @@ HostProcess 容器启动引导的方式造成的。
322
335
<!--
323
336
## Choosing a user account
324
337
325
- HostProcess containers support the ability to run as one of three supported Windows service accounts :
338
+ ### System accounts
339
+
340
+ By default, HostProcess containers support the ability to run as one of three supported Windows service accounts:
326
341
-->
327
342
## 选择用户账号 {#choosing-a-user-account}
328
343
329
- HostProcess 容器支持以三种被支持的 Windows 服务账号之一来运行:
344
+ ### 系统账号 {#system-accounts}
345
+
346
+ 默认情况下,HostProcess 容器支持以三种被支持的 Windows 服务账号之一来运行:
330
347
331
348
- **[LocalSystem](https://docs.microsoft.com/windows/win32/services/localsystem-account)**
332
349
- **[LocalService](https://docs.microsoft.com/windows/win32/services/localservice-account)**
@@ -344,3 +361,104 @@ use the LocalService service account as it is the least privileged of the three
344
361
在三者之中最高,只有在绝对需要的时候才应该使用。只要可能,应该使用
345
362
LocalService 服务账号,因为该账号在三者中特权最低。
346
363
364
+ <!--
365
+ ### Local accounts {#local-accounts}
366
+
367
+ If configured, HostProcess containers can also run as local user accounts which allows for node operators to give
368
+ fine-grained access to workloads.
369
+ -->
370
+ ### 本地账号 {#local-accounts}
371
+
372
+ 取决于配置,HostProcess 容器也能够以本地用户账号运行,
373
+ 从而允许节点操作员为工作负载提供细粒度的访问权限。
374
+
375
+ <!--
376
+ To run HostProcess containers as a local user; A local usergroup must first be created on the node
377
+ and the name of that local usergroup must be specified in the ` runAsUserName` field in the deployment.
378
+ Prior to initializing the HostProcess container, a new **ephemeral** local user account to be created and joined to the specified usergroup, from which the container is run.
379
+ This provides a number a benefits including eliminating the need to manage passwords for local user accounts.
380
+ An initial HostProcess container running as a service account can be used to
381
+ prepare the user groups for later HostProcess containers.
382
+ -->
383
+ 要以本地用户运行 HostProcess 容器,必须首先在节点上创建一个本地用户组,
384
+ 并在部署中在 `runAsUserName` 字段中指定该本地用户组的名称。
385
+ 在初始化 HostProcess 容器之前,将创建一个新的**临时**本地用户账号,并加入到指定的用户组中,
386
+ 使用这个账号来运行容器。这样做有许多好处,包括不再需要管理本地用户账号的密码。
387
+ 作为服务账号运行的初始 HostProcess 容器可用于准备用户组,以供后续的 HostProcess 容器使用。
388
+
389
+ {{< note >}}
390
+ <!--
391
+ Running HostProcess containers as local user accounts requires containerd v1.7+
392
+ -->
393
+ 以本地用户账号运行 HostProcess 容器需要 containerd v1.7+。
394
+ {{< /note >}}
395
+
396
+ <!--
397
+ Example :
398
+
399
+ 1. Create a local user group on the node (this can be done in another HostProcess container).
400
+ -->
401
+ 例如:
402
+
403
+ 1. 在节点上创建本地用户组(这可以在另一个 HostProcess 容器中完成)。
404
+
405
+ ` ` ` cmd
406
+ net localgroup hpc-localgroup /add
407
+ ` ` `
408
+
409
+ <!--
410
+ 1. Grant access to desired resources on the node to the local usergroup.
411
+ This can be done with tools like [icacls](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/icacls).
412
+ -->
413
+ 2. 为本地用户组授予访问所需资源的权限。这可以通过使用
414
+ [icacls](https://learn.microsoft.com/zh-cn/windows-server/administration/windows-commands/icacls)
415
+ 这类工具达成。
416
+
417
+ <!--
418
+ 1. Set `runAsUserName` to the name of the local usergroup for the pod or individual containers.
419
+ -->
420
+ 3. 针对 Pod 或个别容器,将 `runAsUserName` 设置为本地用户组的名称。
421
+
422
+ ` ` ` yaml
423
+ securityContext:
424
+ windowsOptions:
425
+ hostProcess: true
426
+ runAsUserName: hpc-localgroup
427
+ ` ` `
428
+
429
+ <!--
430
+ 1. Schedule the pod!
431
+ -->
432
+ 4. 调度 Pod!
433
+
434
+ <!--
435
+ # # Base Image for HostProcess Containers
436
+
437
+ HostProcess containers can be built from any of the existing [Windows Container base images](https://learn.microsoft.com/virtualization/windowscontainers/manage-containers/container-base-images).
438
+
439
+ Additionally a new base mage has been created just for HostProcess containers!
440
+ For more information please check out the [windows-host-process-containers-base-image github project](https://github.com/microsoft/windows-host-process-containers-base-image#overview).
441
+ -->
442
+ # # HostProcess 容器的基础镜像 {#base-image-for-hostprocess-containers}
443
+
444
+ HostProcess 容器可以基于任何现有的
445
+ [Windows Container 基础镜像](https://learn.microsoft.com/zh-cn/virtualization/windowscontainers/manage-containers/container-base-images)进行构建。
446
+
447
+ 此外,还专为 HostProcess 容器创建了一个新的基础镜像!有关更多信息,请查看
448
+ [windows-host-process-containers-base-image github 项目](https://github.com/microsoft/windows-host-process-containers-base-image#overview)。
449
+
450
+ <!--
451
+ # # Troubleshooting HostProcess containers
452
+
453
+ - HostProcess containers fail to start with `failed to create user process token : failed to logon user: Access is denied.: unknown`
454
+
455
+ Ensure containerd is running as `LocalSystem` or `LocalService` service accounts. User accounts (even Administrator accounts) do not have permissions to create logon tokens for any of the supported [user accounts](#choosing-a-user-account).
456
+ -->
457
+ # # HostProcess 容器的故障排查 {#troubleshooting-hostprocess-containers}
458
+
459
+ - HostProcess 容器因
460
+ `failed to create user process token : failed to logon user: Access is denied.: unknown`
461
+ 启动失败。
462
+
463
+ 确保 containerd 以 `LocalSystem` 或 `LocalService` 服务帐户运行。
464
+ 用户账号(即使是管理员账号)没有权限为任何支持的[用户账号](#choosing-a-user-account)创建登录令牌。
0 commit comments