HostPath
minikube
Kubernetes
storage
local development

HostPath with minikube - Kubernetes

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

hostPath mounts a path from the Kubernetes node's filesystem directly into a pod. In Minikube, that can be useful for local development because there is only one local node and you often want a quick way to share files between the node and a workload. It is convenient, but it is also very specific to single-node development and should not be treated like normal portable Kubernetes storage.

What hostPath really points to in Minikube

The most important detail is that hostPath refers to the filesystem of the Minikube node, not necessarily the filesystem of your laptop directly. Depending on your Minikube driver, the node may be a VM or containerized environment with its own internal paths.

That means a manifest like this:

yaml
1apiVersion: v1
2kind: Pod
3metadata:
4  name: demo-hostpath
5spec:
6  containers:
7    - name: app
8      image: busybox:1.36
9      command: ["sh", "-c", "while true; do sleep 3600; done"]
10      volumeMounts:
11        - name: data
12          mountPath: /data
13  volumes:
14    - name: data
15      hostPath:
16        path: /tmp/demo-data
17        type: DirectoryOrCreate

mounts /tmp/demo-data from the Minikube node into the container at /data. It does not automatically mean "my macOS or Windows host path."

Apply and verify the mount

Once the pod is running, you can verify the behavior from inside the container:

bash
1kubectl apply -f pod.yaml
2kubectl exec -it demo-hostpath -- sh
3echo "hello from pod" > /data/test.txt
4ls -l /data

If you then inspect the same node path, you should see the file created by the container. In Minikube, that can be checked by opening a shell on the node:

bash
minikube ssh
ls -l /tmp/demo-data
cat /tmp/demo-data/test.txt

That is the clearest way to understand what hostPath is doing in a local cluster.

Use Minikube mounts when you need a real host-to-node bridge

If your real goal is to expose a directory from your workstation into the Minikube node, hostPath alone is often not enough. In that case, the usual Minikube workflow is to mount a local directory into the node first, then reference that node path from hostPath.

For example:

bash
minikube mount "$PWD/data:/mnt/data"

Then your pod can use:

yaml
1volumes:
2  - name: data
3    hostPath:
4      path: /mnt/data
5      type: Directory

This two-step model is why many beginners get confused. hostPath is node-local storage, while minikube mount is the bridge from your workstation into that node.

Why hostPath is mostly for development

hostPath is tightly coupled to a specific node. In a real multi-node cluster, a pod rescheduled onto another node would not see the same data unless that path existed there too. That makes hostPath poor for portable production workloads.

In Minikube, that limitation is less severe because the cluster is usually single-node and local. That is why hostPath is reasonable for development experiments, temporary state, or debugging file exchange.

If you want behavior that looks more like real Kubernetes storage, use a PersistentVolume and PersistentVolumeClaim instead of embedding a raw hostPath into every pod spec.

Common Pitfalls

The most common mistake is assuming hostPath points to the laptop filesystem directly. In Minikube it points to the node filesystem, which may or may not already include your local files.

Another issue is using hostPath in examples and then carrying the same pattern into production. It ties workloads to node-specific paths and creates security and portability problems.

Developers also forget that file ownership and permissions still matter. A mounted path can exist and still be unusable from inside the container if permissions do not line up.

Finally, hostPath does not behave like a networked persistent volume. It is a direct node path mount, which is simpler but much less flexible.

Summary

  • 'hostPath mounts a path from the Minikube node into a pod.'
  • In Minikube, that path is node-local, not automatically the workstation filesystem.
  • Use minikube mount first if you need to expose a local workstation directory into the node.
  • 'hostPath is fine for local development, debugging, and simple experiments.'
  • For production-style storage behavior, prefer PV and PVC patterns instead of raw hostPath.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.