---
source: https://iinventedlight.com/library/notes/kubernetes-hostpath.md
title: "Kubernetes hostPath volumes - mount a file or directory from the node"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Volume Types; kubernetes/website (GitHub), volume-types.md. CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubernetes hostpath"
tags: [kubernetes, hostpath, volumes, node, privileged]
client: Librarian
sources:
  - id: S1
    title: "Volume Types"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/reference/storage/volume-types/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "volume-types.md"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/reference/storage/volume-types.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# Kubernetes hostPath volumes - mount a file or directory from the node
**Answer:** A hostPath volume mounts a file or directory from the node's filesystem into a Pod. The `type` field describes what must exist at the given path.

## Example

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: logs
spec:
  containers:
  - name: reader
    image: example/reader
    volumeMounts:
    - mountPath: /logs
      name: nodelogs
      readOnly: true
  volumes:
  - name: nodelogs
    hostPath:
      path: /var/log
      type: Directory
```

## type values

| type | Behavior |
|---|---|
| `""` (default) | no checks before mounting, for backward compatibility |
| `DirectoryOrCreate` | missing path: an empty directory is created, permission 0755 |
| `Directory` | a directory must already exist |
| `FileOrCreate` | create an empty file at 0644 if missing |
| `File` | a file must already exist |

## Rules

- The FileOrCreate mode does not create the parent directory of the file.
- Access to the host filesystem can expose privileged system credentials, such as for the kubelet.

## See also

- [kubernetes-persistent-volumes](https://iinventedlight.com/library/notes/kubernetes-persistent-volumes/)
- [kubernetes-emptydir](https://iinventedlight.com/library/notes/kubernetes-emptydir/)
- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)

## Claims

- id: C1
  claim: FileOrCreate does not create the parent directory.
  source: S1
  evidence: "The FileOrCreate mode does not create the parent directory"

- id: C2
  claim: An empty type string is for backward compatibility.
  source: S1
  evidence: "Empty string (default) is for backward compatibility"

- id: C3
  claim: hostPath mounts a file or directory from the node.
  source: S2
  evidence: "A `hostPath` volume mounts a file or directory"

## Sources

- [S1] Volume Types. Kubernetes docs. https://kubernetes.io/docs/reference/storage/volume-types/ . License: CC-BY-4.0. Accessed 2026-11-18.

- [S2] volume-types.md. kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/reference/storage/volume-types.md . License: CC-BY-4.0. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Volume Types; kubernetes/website (GitHub), volume-types.md. CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
