the*_*ter 4 ubuntu docker kubernetes devops kubernetes-pod
我正在将 ubuntu 18 与 minikube 和虚拟框一起使用,并尝试挂载主机的目录以获取我的 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"
}
}
Run Code Online (Sandbox Code Playgroud)
这个 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
Run Code Online (Sandbox Code Playgroud)
我还尝试根据所谓的默认安装路径创建卷,但没有成功。
我尝试将卷声明添加到作业创建 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 ...
Run Code Online (Sandbox Code Playgroud)
现在打开另一个控制台:
? ~ minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ cat /test-dir/test-file
test-string
Run Code Online (Sandbox Code Playgroud)
编辑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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3299 次 |
最近记录: |