docker - Minikube 挂载的主机文件夹不起作用
问题描述
我正在使用带有 minikube 和虚拟盒的 ubuntu 18,并尝试挂载主机的目录以获取我的 pod 需要的输入数据。
我发现 minikube 有挂载主机目录的问题,但是根据您的操作系统和 vm 驱动程序,默认情况下,有些目录是默认挂载的
我在我的豆荚上找不到那些。他们根本不在那里。
我试图创建一个持久卷,它可以工作,我可以在仪表板上看到它,但我无法将它安装到 pod,我使用这个 yaml 来创建卷
{
"kind": "PersistentVolume",
"apiVersion": "v1",
"metadata": {
"name": "pv0003",
"selfLink": "/api/v1/persistentvolumes/pv0001",
"uid": "28038976-9ee4-414d-8478-b312a24a6b94",
"resourceVersion": "2030",
"creationTimestamp": "2019-08-08T10:48:23Z",
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"PersistentVolume\",\"metadata\":{\"annotations\":{},\"name\":\"pv0001\"},\"spec\":{\"accessModes\":[\"ReadWriteOnce\"],\"capacity\":{\"storage\":\"5Gi\"},\"hostPath\":{\"path\":\"/data/pv0001/\"}}}\n"
},
"finalizers": [
"kubernetes.io/pv-protection"
]
},
"spec": {
"capacity": {
"storage": "6Gi"
},
"hostPath": {
"path": "/user/data",
"type": ""
},
"accessModes": [
"ReadWriteOnce"
],
"persistentVolumeReclaimPolicy": "Retain",
"volumeMode": "Filesystem"
},
"status": {
"phase": "Available"
}
}
而这个 yaml 来创建工作。
apiVersion: batch/v1
kind: Job
metadata:
name: pi31
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["sleep"]
args: ["300"]
volumeMounts:
- mountPath: /data
name: pv0003
volumes:
- name: pv0003
hostPath:
path: /user/data
restartPolicy: Never
backoffLimit: 1
我还尝试根据所谓的默认安装路径创建卷,但没有成功。
我试图将卷声明添加到作业创建 yaml 中,仍然没有。
当我挂载驱动器并在作业创建 yaml 文件中创建它们时,作业能够看到其他作业创建的数据,但它对主机是不可见的,并且主机的数据对它们是不可见的。
我正在从我的主要用户运行 minikube,并检查了仪表板中的日志,没有收到任何权限错误
有什么方法可以在不设置 NFS 的情况下将数据导入这个 minikube?我正在尝试将它用于 MVP,整个想法是让它变得简单......
解决方案
这并不容易,因为 minikube 在 Virtualbox 中创建的 VM 中工作,这就是为什么使用 hostPath 您会看到该 VM 的文件系统而不是您的 PC。
我真的建议使用minikube mount
命令 - 你可以在那里找到描述
来自文档:
minikube mount /path/to/dir/to/mount:/vm-mount-path 是将目录挂载到 minikube 的推荐方式,以便它们可以在本地 Kubernetes 集群中使用。
因此,之后您可以在 minikube Kubernetes 中共享主机的文件。
编辑:
这是逐步记录如何测试它的方法:
➜ ~ minikube start
* minikube v1.3.0 on Ubuntu 19.04
* Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
* Starting existing virtualbox VM for "minikube" ...
* Waiting for the host to be provisioned ...
* Preparing Kubernetes v1.15.2 on Docker 18.09.6 ...
* Relaunching Kubernetes using kubeadm ...
* Waiting for: apiserver proxy etcd scheduler controller dns
* Done! kubectl is now configured to use "minikube"
➜ ~ mkdir -p /tmp/test-dir
➜ ~ echo "test-string" > /tmp/test-dir/test-file
➜ ~ minikube mount /tmp/test-dir:/test-dir
* Mounting host path /tmp/test-dir into VM as /test-dir ...
- Mount type: <no value>
- User ID: docker
- Group ID: docker
- Version: 9p2000.L
- Message Size: 262144
- Permissions: 755 (-rwxr-xr-x)
- Options: map[]
* Userspace file server: ufs starting
* Successfully mounted /tmp/test-dir to /test-dir
* NOTE: This process must stay alive for the mount to be accessible ...
现在打开另一个控制台:
➜ ~ minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ cat /test-dir/test-file
test-string
编辑2:
示例作业.yml
apiVersion: batch/v1
kind: Job
metadata:
name: test
spec:
template:
spec:
containers:
- name: test
image: ubuntu
command: ["cat", "/testing/test-file"]
volumeMounts:
- name: test-volume
mountPath: /testing
volumes:
- name: test-volume
hostPath:
path: /test-dir
restartPolicy: Never
backoffLimit: 4
推荐阅读
- graphql - 无法在类型“用户”graphql 上查询字段“密码”
- android - 多按钮点击事件
- scala - 为什么 pureconfig 找不到我的隐式读者?
- react-native - 从数组中删除特定项目 - 反应原生
- python - 如何处理读取、提取和保存具有 Angular 客户端和 Django 服务器的超大 csv 或 excel 数据
- ruby - 如何删除字符串的一部分?
- php - 在 PHP5 中的 PHP7 中工作的代码的替代方案是什么
- r - 特定于包的 utils::news() 在 RStudio 中不起作用
- asp.net-mvc - 如何优化查询EF的速度
- hive - 蜂巢表中的“位置”和“路径”有什么区别