将本地目录挂载到

将本地目录挂载到

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

问题描述

我正在运行minikube v0.24.1.在这个迷你kube中,我将为我的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.

还有另一种方式

主机的$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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:56