'Create folder mounting between localhost and minikube services
I have some trouble creating a mounting folder between my local host (Ubuntu 20.04) to my services running on minikube. I want multiple containers to share files (one container will write, and the others will read).
The services have a simple Python script that gets a path to a folder:
with open('/MountedFolder/MyFile.txt', 'w') as f:
f.write("New Text")
And I have a simple deployment file that looks like that:
apiVersion: apps/v1
kind: Deployment
metadata:
name: info-deployment
labels:
app: info
spec:
replicas: 1
selector:
matchLabels:
app: info
template:
metadata:
labels:
app: info
spec:
containers:
- name: info
image: info:1.0
ports:
- containerPort: 8081
I succeeded in getting a mounted folder as a URL (http://localhost). Using this guide:
https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
However, I am looking for a “path” like mounting (/MountedFolder/MyFile.txt) on the host.
Is it possible? If so, how?
Solution 1:[1]
If you used the PVC-Guide (https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/)
Change your python to:
with open('[mountPath]/MyFile.txt', 'w') as f:
f.write("New Text")
The file will then be created under: [mountPath]/MyFile.txt, where [mountPath] is set in your container spec. From pod viewpoint.
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
On the host you should find the file under:
"/mnt/data/MyFile.txt"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
