将本地目录挂载到 minikube 的 pod 中 [英] Mount local directory into pod in minikube

查看:93
本文介绍了将本地目录挂载到 minikube 的 pod 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 minikube v0.24.1.在这个 minikube 中,我将为我的 nginx 应用程序创建一个 Pod.而且我还想从我的本地目录传递数据.

I am running minikube v0.24.1. In this minikube, I will create a Pod for my nginx application. And also I want to pass data from my local directory.

这意味着我想将我的本地 $HOME/go/src/github.com/nginx 挂载到我的 Pod 中

That means I want to mount my local $HOME/go/src/github.com/nginx into my Pod

我该怎么做?

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - image: nginx:0.1
    name: nginx
    volumeMounts:
    - mountPath: /data
      name: volume
  volumes:
  - name: volume
    hostPath:
      path: /data

推荐答案

您不能直接将本地目录挂载到 Pod 中.

You can't mount your local directory into your Pod directly.

首先,您需要将目录 $HOME/go/src/github.com/nginx 挂载到您的 minikube 中.

First, you need to mount your directory $HOME/go/src/github.com/nginx into your minikube.

$ minikube start --mount-string="$HOME/go/src/github.com/nginx:/data"

然后,如果您使用 hostPath 将 /data 挂载到您的 Pod 中,您会将本地目录数据放入 Pod.

Then If you mount /data into your Pod using hostPath, you will get you local directory data into Pod.

还有另一种方式

Host 的 $HOME 目录被挂载到 minikube 的 /hosthome 目录中.在这里你会得到你的数据

Host's $HOME directory gets mounted into minikube's /hosthome directory. Here you will get your data

$ ls -la /hosthome/go/src/github.com/nginx

所以要挂载这个目录,你可以改变你的Pod的hostPath

So to mount this directory, you can change your Pod's hostPath

hostPath:
  path: /hosthome/go/src/github.com/nginx

这篇关于将本地目录挂载到 minikube 的 pod 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆