You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -349,92 +349,161 @@ and then removed entirely in the v1.26 release.
349
349
350
350
### hostPath {#hostpath}
351
351
352
+
A `hostPath` volume mounts a file or directory from the host node's filesystem
353
+
into your Pod. This is not something that most Pods will need, but it offers a
354
+
powerful escape hatch for some applications.
355
+
352
356
{{< warning >}}
353
-
HostPath volumes present many security risks, and it is a best practice to avoid the use of
354
-
HostPaths when possible. When a HostPath volume must be used, it should be scoped to only the
355
-
required file or directory, and mounted as ReadOnly.
357
+
Using the `hostPath` volume type presents many security risks.
358
+
If you can avoid using a `hostPath` volume, you should. For example,
359
+
define a [`local` PersistentVolume](#local), and use that instead.
360
+
361
+
If you are restricting access to specific directories on the node using
362
+
admission-time validation, that restriction is only effective when you
363
+
additionally require that any mounts of that `hostPath` volume are
364
+
**read only**. If you allow a read-write mount of any host path by an
365
+
untrusted Pod, the containers in that Pod may be able to subvert the
366
+
read-write host mount.
367
+
368
+
---
369
+
370
+
Take care when using `hostPath` volumes, whether these are mounted as read-only
371
+
or as read-write, because:
356
372
357
-
If restricting HostPath access to specific directories through AdmissionPolicy, `volumeMounts` MUST
358
-
be required to use `readOnly` mounts for the policy to be effective.
373
+
* Access to the host filesystem can expose privileged system credentials (such as for the kubelet) or privileged APIs
374
+
(such as the container runtime socket), that can be used for container escape or to attack other
375
+
parts of the cluster.
376
+
* Pods with identical configuration (such as created from a PodTemplate) may
377
+
behave differently on different nodes due to different files on the nodes.
359
378
{{< /warning >}}
360
379
361
-
A `hostPath` volume mounts a file or directory from the host node's filesystem
362
-
into your Pod. This is not something that most Pods will need, but it offers a
363
-
powerful escape hatch for some applications.
380
+
Some uses for a `hostPath` are:
381
+
382
+
* running a container that needs access to node-level system components
383
+
(such as a container that transfers system logs to a central location,
384
+
accessing those logs using a read-only mount of `/var/log`)
385
+
* making a configuration file stored on the host system available read-only
386
+
to a {{< glossary_tooltip text="static pod" term_id="static-pod" >}};
387
+
unlike normal Pods, static Pods cannot access ConfigMaps
364
388
365
-
For example, some uses for a `hostPath` are:
389
+
#### `hostPath` volume types
366
390
367
-
* running a container that needs access to Docker internals; use a `hostPath`
368
-
of `/var/lib/docker`
369
-
* running cAdvisor in a container; use a `hostPath` of `/sys`
370
-
* allowing a Pod to specify whether a given `hostPath` should exist prior to the
371
-
Pod running, whether it should be created, and what it should exist as
391
+
In addition to the required `path` property, you can optionally specify a
392
+
`type`for a `hostPath` volume.
372
393
373
-
In addition to the required `path` property, you can optionally specify a `type` for a `hostPath` volume.
394
+
The available values for `type` are:
374
395
375
-
The supported values for field `type` are:
396
+
<!-- empty string represented using U+200C ZERO WIDTH NON-JOINER -->
376
397
377
398
| Value | Behavior |
378
399
|:------|:---------|
379
-
| | Empty string (default) is for backward compatibility, which means that no checks will be performed before mounting the hostPath volume. |
400
+
| `""` | Empty string (default) is for backward compatibility, which means that no checks will be performed before mounting the `hostPath` volume. |
380
401
| `DirectoryOrCreate` | If nothing exists at the given path, an empty directory will be created there as needed with permission set to 0755, having the same group and ownership with Kubelet. |
381
402
| `Directory` | A directory must exist at the given path |
382
403
| `FileOrCreate` | If nothing exists at the given path, an empty file will be created there as needed with permission set to 0644, having the same group and ownership with Kubelet. |
383
404
| `File` | A file must exist at the given path |
384
405
| `Socket` | A UNIX socket must exist at the given path |
385
-
| `CharDevice` | A character device must exist at the given path |
386
-
| `BlockDevice` | A block device must exist at the given path |
406
+
| `CharDevice` | _(Linux nodes only)_ A character device must exist at the given path |
407
+
| `BlockDevice` | _(Linux nodes only)_ A block device must exist at the given path |
387
408
388
-
Watch out when using this type of volume, because:
409
+
{{< caution >}}
410
+
The `FileOrCreate` mode does **not** create the parent directory of the file. If the parent directory
411
+
of the mounted file does not exist, the pod fails to start. To ensure that this mode works,
412
+
you can try to mount directories and files separately, as shown in the
413
+
[`FileOrCreate` example](#hostpath-fileorcreate-example) for `hostPath`.
414
+
{{< /caution >}}
389
415
390
-
* HostPaths can expose privileged system credentials (such as for the Kubelet) or privileged APIs
391
-
(such as container runtime socket), which can be used for container escape or to attack other
392
-
parts of the cluster.
393
-
* Pods with identical configuration (such as created from a PodTemplate) may
394
-
behave differently on different nodes due to different files on the nodes
395
-
* The files or directories created on the underlying hosts are only writable by root. You
396
-
either need to run your process as root in a
397
-
[privileged Container](/docs/tasks/configure-pod-container/security-context/) or modify the file
398
-
permissions on the host to be able to write to a `hostPath` volume
416
+
Some files or directories created on the underlying hosts might only be
417
+
accessible by root. You then either need to run your process as root in a
0 commit comments