2021-07-27 07:50:45 +00:00
|
|
|
---
|
|
|
|
title: Create a Windows HostProcess Pod
|
|
|
|
content_type: task
|
|
|
|
weight: 20
|
2021-12-06 21:07:33 +00:00
|
|
|
min-kubernetes-server-version: 1.23
|
2021-07-27 07:50:45 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
<!-- overview -->
|
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
{{< feature-state for_k8s_version="v1.23" state="beta" >}}
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
Windows HostProcess containers enable you to run containerized
|
|
|
|
workloads on a Windows host. These containers operate as
|
|
|
|
normal processes but have access to the host network namespace,
|
|
|
|
storage, and devices when given the appropriate user privileges.
|
2021-07-27 07:50:45 +00:00
|
|
|
HostProcess containers can be used to deploy network plugins,
|
2021-11-30 23:49:17 +00:00
|
|
|
storage configurations, device plugins, kube-proxy, and other
|
|
|
|
components to Windows nodes without the need for dedicated proxies or
|
2021-07-27 07:50:45 +00:00
|
|
|
the direct installation of host services.
|
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
Administrative tasks such as installation of security patches, event
|
|
|
|
log collection, and more can be performed without requiring cluster operators to
|
2022-04-09 14:52:46 +00:00
|
|
|
log onto each Windows node. HostProcess containers can run as any user that is
|
2021-11-30 23:49:17 +00:00
|
|
|
available on the host or is in the domain of the host machine, allowing administrators
|
|
|
|
to restrict resource access through user permissions. While neither filesystem or process
|
|
|
|
isolation are supported, a new volume is created on the host upon starting the container
|
|
|
|
to give it a clean and consolidated workspace. HostProcess containers can also be built on
|
|
|
|
top of existing Windows base images and do not inherit the same
|
|
|
|
[compatibility requirements](https://docs.microsoft.com/virtualization/windowscontainers/deploy-containers/version-compatibility)
|
|
|
|
as Windows server containers, meaning that the version of the base images does not need
|
|
|
|
to match that of the host. It is, however, recommended that you use the same base image
|
|
|
|
version as your Windows Server container workloads to ensure you do not have any unused
|
|
|
|
images taking up space on the node. HostProcess containers also support
|
2022-02-05 04:55:03 +00:00
|
|
|
[volume mounts](#volume-mounts) within the container volume.
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
### When should I use a Windows HostProcess container?
|
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
- When you need to perform tasks which require the networking namespace of the host.
|
2021-07-27 07:50:45 +00:00
|
|
|
HostProcess containers have access to the host's network interfaces and IP addresses.
|
|
|
|
- You need access to resources on the host such as the filesystem, event logs, etc.
|
|
|
|
- Installation of specific device drivers or Windows services.
|
2021-11-30 23:49:17 +00:00
|
|
|
- Consolidation of administrative tasks and security policies. This reduces the degree of
|
2021-07-27 07:50:45 +00:00
|
|
|
privileges needed by Windows nodes.
|
|
|
|
|
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
## {{% heading "prerequisites" %}}
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
<!-- change this when graduating to stable -->
|
|
|
|
|
|
|
|
This task guide is specific to Kubernetes v{{< skew currentVersion >}}.
|
|
|
|
If you are not running Kubernetes v{{< skew currentVersion >}}, check the documentation for
|
|
|
|
that version of Kubernetes.
|
|
|
|
|
|
|
|
In Kubernetes {{< skew currentVersion >}}, the HostProcess container feature is enabled by default. The kubelet will
|
2021-11-30 23:49:17 +00:00
|
|
|
communicate with containerd directly by passing the hostprocess flag via CRI. You can use the
|
|
|
|
latest version of containerd (v1.6+) to run HostProcess containers.
|
|
|
|
[How to install containerd.](/docs/setup/production-environment/container-runtimes/#containerd)
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
To *disable* HostProcess containers you need to pass the following feature gate flag to the
|
|
|
|
**kubelet** and **kube-apiserver**:
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
```powershell
|
|
|
|
--feature-gates=WindowsHostProcessContainers=false
|
2021-07-27 07:50:45 +00:00
|
|
|
```
|
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
See [Features Gates](/docs/reference/command-line-tools-reference/feature-gates/#overview)
|
|
|
|
documentation for more details.
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Limitations
|
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
These limitations are relevant for Kubernetes v{{< skew currentVersion >}}:
|
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
- HostProcess containers require containerd 1.6 or higher
|
2022-02-05 04:55:03 +00:00
|
|
|
{{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}.
|
2021-12-06 21:07:33 +00:00
|
|
|
- HostProcess pods can only contain HostProcess containers. This is a current limitation
|
2022-02-05 04:55:03 +00:00
|
|
|
of the Windows OS; non-privileged Windows containers cannot share a vNIC with the host IP namespace.
|
2021-11-30 23:49:17 +00:00
|
|
|
- HostProcess containers run as a process on the host and do not have any degree of
|
2022-02-05 04:55:03 +00:00
|
|
|
isolation other than resource constraints imposed on the HostProcess user account. Neither
|
|
|
|
filesystem or Hyper-V isolation are supported for HostProcess containers.
|
|
|
|
- Volume mounts are supported and are mounted under the container volume. See
|
|
|
|
[Volume Mounts](#volume-mounts)
|
2021-12-06 04:02:33 +00:00
|
|
|
- A limited set of host user accounts are available for HostProcess containers by default.
|
2021-12-06 21:07:33 +00:00
|
|
|
See [Choosing a User Account](#choosing-a-user-account).
|
2021-11-30 23:49:17 +00:00
|
|
|
- Resource limits (disk, memory, cpu count) are supported in the same fashion as processes
|
2022-02-05 04:55:03 +00:00
|
|
|
on the host.
|
2021-12-06 21:07:33 +00:00
|
|
|
- Both Named pipe mounts and Unix domain sockets are **not** supported and should instead
|
2022-02-05 04:55:03 +00:00
|
|
|
be accessed via their path on the host (e.g. \\\\.\\pipe\\\*)
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
## HostProcess Pod configuration requirements
|
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
Enabling a Windows HostProcess pod requires setting the right configurations in the pod security
|
|
|
|
configuration. Of the policies defined in the [Pod Security Standards](/docs/concepts/security/pod-security-standards)
|
|
|
|
HostProcess pods are disallowed by the baseline and restricted policies. It is therefore recommended
|
|
|
|
that HostProcess pods run in alignment with the privileged profile.
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
When running under the privileged policy, here are
|
|
|
|
the configurations which need to be set to enable the creation of a HostProcess pod:
|
|
|
|
|
|
|
|
<table>
|
2021-12-06 21:07:33 +00:00
|
|
|
<caption style="display: none">Privileged policy specification</caption>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Control</th>
|
|
|
|
<th>Policy</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td style="white-space: nowrap"><a href="/docs/concepts/security/pod-security-standards"><tt>securityContext.windowsOptions.hostProcess</tt></a></td>
|
|
|
|
<td>
|
|
|
|
<p>Windows pods offer the ability to run <a href="/docs/tasks/configure-pod-container/create-hostprocess-pod">
|
2021-07-27 07:50:45 +00:00
|
|
|
HostProcess containers</a> which enables privileged access to the Windows node. </p>
|
2021-12-06 21:07:33 +00:00
|
|
|
<p><strong>Allowed Values</strong></p>
|
|
|
|
<ul>
|
|
|
|
<li><code>true</code></li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td style="white-space: nowrap"><a href="/docs/concepts/security/pod-security-standards"><tt>hostNetwork</tt></a></td>
|
|
|
|
<td>
|
|
|
|
<p>Will be in host network by default initially. Support
|
|
|
|
to set network to a different compartment may be desirable in
|
|
|
|
the future.</p>
|
|
|
|
<p><strong>Allowed Values</strong></p>
|
|
|
|
<ul>
|
|
|
|
<li><code>true</code></li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2021-07-27 07:50:45 +00:00
|
|
|
<tr>
|
2021-12-06 21:07:33 +00:00
|
|
|
<td style="white-space: nowrap"><a href="/docs/tasks/configure-pod-container/configure-runasusername/"><tt>securityContext.windowsOptions.runAsUsername</tt></a></td>
|
|
|
|
<td>
|
|
|
|
<p>Specification of which user the HostProcess container should run as is required for the pod spec.</p>
|
|
|
|
<p><strong>Allowed Values</strong></p>
|
|
|
|
<ul>
|
|
|
|
<li><code>NT AUTHORITY\SYSTEM</code></li>
|
|
|
|
<li><code>NT AUTHORITY\Local service</code></li>
|
|
|
|
<li><code>NT AUTHORITY\NetworkService</code></li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2021-07-27 07:50:45 +00:00
|
|
|
<tr>
|
2021-12-06 21:07:33 +00:00
|
|
|
<td style="white-space: nowrap"><a href="/docs/concepts/security/pod-security-standards"><tt>runAsNonRoot</tt></a></td>
|
|
|
|
<td>
|
|
|
|
<p>Because HostProcess containers have privileged access to the host, the <tt>runAsNonRoot</tt> field cannot be set to true.</p>
|
|
|
|
<p><strong>Allowed Values</strong></p>
|
|
|
|
<ul>
|
2021-07-27 07:50:45 +00:00
|
|
|
<li>Undefined/Nil</li>
|
2021-12-06 21:07:33 +00:00
|
|
|
<li><code>false</code></li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
2021-07-27 07:50:45 +00:00
|
|
|
</table>
|
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
### Example manifest (excerpt) {#manifest-example}
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
spec:
|
|
|
|
securityContext:
|
|
|
|
windowsOptions:
|
|
|
|
hostProcess: true
|
|
|
|
runAsUserName: "NT AUTHORITY\\Local service"
|
|
|
|
hostNetwork: true
|
|
|
|
containers:
|
|
|
|
- name: test
|
|
|
|
image: image1:latest
|
|
|
|
command:
|
|
|
|
- ping
|
|
|
|
- -t
|
|
|
|
- 127.0.0.1
|
|
|
|
nodeSelector:
|
|
|
|
"kubernetes.io/os": windows
|
|
|
|
```
|
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
## Volume mounts
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
HostProcess containers support the ability to mount volumes within the container volume space.
|
|
|
|
Applications running inside the container can access volume mounts directly via relative or
|
2021-12-06 21:07:33 +00:00
|
|
|
absolute paths. An environment variable `$CONTAINER_SANDBOX_MOUNT_POINT` is set upon container
|
2021-11-30 23:49:17 +00:00
|
|
|
creation and provides the absolute host path to the container volume. Relative paths are based
|
2021-12-06 21:07:33 +00:00
|
|
|
upon the `.spec.containers.volumeMounts.mountPath` configuration.
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
### Example {#volume-mount-example}
|
|
|
|
|
|
|
|
To access service account tokens the following path structures are supported within the container:
|
|
|
|
|
|
|
|
`.\var\run\secrets\kubernetes.io\serviceaccount\`
|
|
|
|
|
|
|
|
`$CONTAINER_SANDBOX_MOUNT_POINT\var\run\secrets\kubernetes.io\serviceaccount\`
|
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
## Resource limits
|
2021-11-30 23:49:17 +00:00
|
|
|
|
|
|
|
Resource limits (disk, memory, cpu count) are applied to the job and are job wide.
|
|
|
|
For example, with a limit of 10MB set, the memory allocated for any HostProcess job object
|
|
|
|
will be capped at 10MB. This is the same behavior as other Windows container types.
|
|
|
|
These limits would be specified the same way they are currently for whatever orchestrator
|
|
|
|
or runtime is being used. The only difference is in the disk resource usage calculation
|
|
|
|
used for resource tracking due to the difference in how HostProcess containers are bootstrapped.
|
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
## Choosing a user account
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-12-06 21:07:33 +00:00
|
|
|
HostProcess containers support the ability to run as one of three supported Windows service accounts:
|
2021-07-27 07:50:45 +00:00
|
|
|
|
2021-11-30 23:49:17 +00:00
|
|
|
- **[LocalSystem](https://docs.microsoft.com/windows/win32/services/localsystem-account)**
|
|
|
|
- **[LocalService](https://docs.microsoft.com/windows/win32/services/localservice-account)**
|
|
|
|
- **[NetworkService](https://docs.microsoft.com/windows/win32/services/networkservice-account)**
|
2021-07-27 07:50:45 +00:00
|
|
|
|
|
|
|
You should select an appropriate Windows service account for each HostProcess
|
|
|
|
container, aiming to limit the degree of privileges so as to avoid accidental (or even
|
|
|
|
malicious) damage to the host. The LocalSystem service account has the highest level
|
|
|
|
of privilege of the three and should be used only if absolutely necessary. Where possible,
|
|
|
|
use the LocalService service account as it is the least privileged of the three options.
|