|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.26: Windows HostProcess Containers Are Going Generally Available" |
| 4 | +date: 2022-12-13 |
| 5 | +slug: windows-host-process-containers-ga |
| 6 | +--- |
| 7 | + |
| 8 | +**Authors**: Brandon Smith (Microsoft) and Mark Rossetti (Microsoft) |
| 9 | + |
| 10 | +The long-awaited day has arrived: HostProcess containers, the Windows equivalent to Linux privileged |
| 11 | +containers, has finally made it to **GA in Kubernetes 1.26**! |
| 12 | + |
| 13 | +What are HostProcess containers and why are they useful? |
| 14 | + |
| 15 | +Cluster operators are often faced with the need to configure their nodes upon provisioning. Whether it's |
| 16 | +installing Windows services, configuring registry keys, managing TLS certificates, |
| 17 | +making network configuration changes, or even deploying monitoring tools such as a Prometheus's node-exporter. |
| 18 | +Previously, performing these actions on Windows nodes was usually done by running PowerShell scripts |
| 19 | +over SSH or WinRM sessions and/or working with your cloud provider's virtual machine management tooling. |
| 20 | +HostProcess containers now enable you to do all of this and more with minimal effort. |
| 21 | + |
| 22 | +With HostProcess containers you can now package any payload |
| 23 | +into the container image, map volumes into containers at runtime, and manage them like any other Kubernetes workload. |
| 24 | +You get all the benefits of containerized packaging and deployment methods combined with a reduction in |
| 25 | +both administrative and development cost. |
| 26 | +Gone are the days where cluster operators would need to manually log onto |
| 27 | +Windows nodes to perform administrative duties. |
| 28 | + |
| 29 | +[HostProcess containers](/docs/tasks/configure-pod-container/create-hostprocess-pod/) differ |
| 30 | +quite significantly from regular Windows Server containers. |
| 31 | +They are run directly as processes on the host under the access policies of |
| 32 | +a user you specify. HostProcess containers run as either the built-in Windows system accounts or |
| 33 | +ephemeral users within a user group defined by you. HostProcess containers also share |
| 34 | +the host's network namespace and access/configure storage mounts visible to the host. |
| 35 | +On the other hand, Windows Server containers are highly isolated and exist in a separate |
| 36 | +execution namespace. Direct access to the host from a Windows Server container is explicitly disallowed |
| 37 | +by default. |
| 38 | + |
| 39 | +## How does it work? |
| 40 | + |
| 41 | +Windows HostProcess containers are implemented with Windows [_Job Objects_](https://learn.microsoft.com/en-us/windows/win32/procthread/job-objects), |
| 42 | +a break from the previous container model which use server silos. |
| 43 | +Job Objects are components of the Windows OS which offer the ability to |
| 44 | +manage a group of processes as a group (also known as a _job_) and assign resource constraints to the |
| 45 | +group as a whole. Job objects are specific to the Windows OS and are not associated with |
| 46 | +the Kubernetes [Job API](/docs/concepts/workloads/controllers/job/). They have no process |
| 47 | +or file system isolation, |
| 48 | +enabling the privileged payload to view and edit the host file system with the |
| 49 | +desired permissions, among other host resources. The init process, and any processes |
| 50 | +it launches (including processes explicitly launched by the user) are all assigned to the |
| 51 | +job object of that container. When the init process exits or is signaled to exit, |
| 52 | +all the processes in the job will be signaled to exit, the job handle will be |
| 53 | +closed and the storage will be unmounted. |
| 54 | + |
| 55 | +HostProcess and Linux privileged containers enable similar scenarios but differ |
| 56 | +greatly in their implementation (hence the naming difference). HostProcess containers |
| 57 | +have their own [PodSecurityContext](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#windowssecuritycontextoptions-v1-core) fields. |
| 58 | +Those used to configure Linux privileged containers **do not** apply. Enabling privileged access to a Windows host is a |
| 59 | +fundamentally different process than with Linux so the configuration and |
| 60 | +capabilities of each differ significantly. Below is a diagram detailing the |
| 61 | +overall architecture of Windows HostProcess containers: |
| 62 | + |
| 63 | +{{< figure src="hpc_architecture.svg" alt="HostProcess Architecture" >}} |
| 64 | + |
| 65 | +Two major features were added prior to moving to stable: the ability to run as local user accounts, and |
| 66 | +a simplified method of accessing volume mounts. To learn more, read |
| 67 | +[Create a Windows HostProcess Pod](/docs/tasks/configure-pod-container/create-hostprocess-pod/). |
| 68 | + |
| 69 | +## HostProcess containers in action |
| 70 | + |
| 71 | +Kubernetes SIG Windows has been busy putting HostProcess containers to use - even before GA! |
| 72 | +They've been very excited to use HostProcess containers for a number of important activities |
| 73 | +that were a pain to perform in the past. |
| 74 | + |
| 75 | +Here are just a few of the many use use cases with example deployments: |
| 76 | + |
| 77 | +- [CNI solutions and kube-proxy](https://github.com/kubernetes-sigs/sig-windows-tools/tree/master/hostprocess/calico#calico-example) |
| 78 | +- [windows-exporter](https://github.com/prometheus-community/windows_exporter/blob/master/kubernetes/windows-exporter-daemonset.yaml) |
| 79 | +- [csi-proxy](https://github.com/kubernetes-sigs/sig-windows-tools/tree/master/hostprocess/csi-proxy) |
| 80 | +- [Windows-debug container](https://github.com/jsturtevant/windows-debug) |
| 81 | +- [ETW event streaming](https://github.com/kubernetes-sigs/sig-windows-tools/tree/master/hostprocess/eventflow-logger) |
| 82 | + |
| 83 | +## How do I use it? |
| 84 | + |
| 85 | +A HostProcess container can be built using any base image of your choosing, however, for convenience we have |
| 86 | +created [a HostProcess container base image](https://github.com/microsoft/windows-host-process-containers-base-image). |
| 87 | +This image is only a few KB in size and does not inherit any of the same compatibility requirements as regular Windows |
| 88 | +server containers which allows it to run on any Windows server version. |
| 89 | + |
| 90 | +To use that Microsoft image, put this in your `Dockerfile`: |
| 91 | + |
| 92 | +```dockerfile |
| 93 | +FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 |
| 94 | +``` |
| 95 | + |
| 96 | +You can run HostProcess containers from within a |
| 97 | +[HostProcess Pod](/docs/concepts/workloads/pods/#privileged-mode-for-containers). |
| 98 | + |
| 99 | +To get started with running Windows containers, |
| 100 | +see the general guidance for [deploying Windows nodes](/docs/setup/production-environment/windows/). |
| 101 | +If you have a compatible node (for example: Windows as the operating system |
| 102 | +containerd v1.7 or later), you can deploy a Pod with one |
| 103 | +or more HostProcess containers. |
| 104 | +See the [Create a Windows HostProcess Pod - Prerequisites](/docs/tasks/configure-pod-container/create-hostprocess-pod/#before-you-begin) |
| 105 | +for more information. |
| 106 | + |
| 107 | +Please note that within a Pod, you can't mix HostProcess containers with normal Windows containers. |
| 108 | + |
| 109 | +## How can I learn more? |
| 110 | + |
| 111 | +- Work through [Create a Windows HostProcess Pod](/docs/tasks/configure-pod-container/create-hostprocess-pod/) |
| 112 | + |
| 113 | +- Read about Kubernetes [Pod Security Standards](/docs/concepts/security/pod-security-standards/) and [Pod Security Admission](docs/concepts/security/pod-security-admission/) |
| 114 | + |
| 115 | +- Read the enhancement proposal [Windows Privileged Containers and Host Networking Mode](https://github.com/kubernetes/enhancements/tree/master/keps/sig-windows/1981-windows-privileged-container-support) (KEP-1981) |
| 116 | + |
| 117 | +- Watch the [Windows HostProcess for Configuration and Beyond](https://www.youtube.com/watch?v=LcXT9pVkwvo) KubeCon NA 2022 talk |
| 118 | + |
| 119 | +## How do I get involved? |
| 120 | + |
| 121 | +Get involved with [SIG Windows](https://github.com/kubernetes/community/tree/master/sig-windows) |
| 122 | +to contribute! |
0 commit comments