Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

docker - HostPath with minikube - Kubernetes

UPDATE: I connected to the minikubevm and I see my host directory mounted but there is no files there. Also when I create a file there it will not in my host machine. Any link are between them

I try to mount an host directory for developing my app with kubernetes.

As the doc recommended, I am using minikube for running my kubernetes cluster on my pc. The goal is to create a develop environment with docker and kubernetes for develop my app. I want to mount a local directory so my docker will read the code app from there. But it is not work. Any help would be really appreciate.

my test app (server.js):

var http = require('http');
var handleRequest = function(request, response) {
response.writeHead(200);
response.end("Hello World!");
}
var www = http.createServer(handleRequest);
www.listen(8080);

my Dockerfile:

FROM node:latest
WORKDIR /code
ADD code/ /code
EXPOSE 8080
CMD server.js

my pod kubernetes configuration: (pod-configuration.yaml)

apiVersion: v1
kind: Pod
metadata:
  name: apiserver
spec:
  containers:
  - name: node
    image: myusername/nodetest:v1
    ports:
    - containerPort: 8080
    volumeMounts:
    - name: api-server-code-files
      mountPath: /code
  volumes:
  - name: api-server-code-files
    hostPath:
      path: /home/<myuser>/Projects/nodetest/api-server/code

my folder are:

/home/<myuser>/Projects/nodetest/
- pod-configuration.yaml
- api-server/
    - Dockerfile
    - code/
        - server.js

When I running my docker image without the hostPath volume it is of course works but the problem is that on each change I will must recreate my image that is really not powerful for development, that's why I need the volume hostPath.

Any idea ? why i don't success to mount my local directory ?

Thanks for the help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...