Eli*_*uzi 19 docker google-cloud-platform kubernetes dockerfile docker-volume
更新:我连接到minikubevm,我看到我的主机目录已安装,但那里没有文件.此外,当我在那里创建一个文件时,它不会在我的主机中.他们之间有任何联系
我尝试使用kubernetes安装主机目录以开发我的应用程序.
正如文档推荐的那样,我使用minikube在我的电脑上运行我的kubernetes集群.目标是使用docker和kubernetes创建开发环境以开发我的应用程序.我想挂载一个本地目录,以便我的docker从那里读取代码应用程序.但这不起作用.任何帮助都会非常感激.
我的测试应用程序(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);
Run Code Online (Sandbox Code Playgroud)
我的Dockerfile:
FROM node:latest
WORKDIR /code
ADD code/ /code
EXPOSE 8080
CMD server.js
Run Code Online (Sandbox Code Playgroud)
我的pod kubernetes配置:(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
Run Code Online (Sandbox Code Playgroud)
我的文件夹是:
/home/<myuser>/Projects/nodetest/
- pod-configuration.yaml
- api-server/
- Dockerfile
- code/
- server.js
Run Code Online (Sandbox Code Playgroud)
当我在没有hostPath卷的情况下运行docker镜像时,它当然有效,但问题是每次更改时我都必须重新创建我的图像,这对于开发来说真的不强大,这就是我需要卷hostPath的原因.
任何的想法 ?为什么我没有成功挂载我的本地目录?
谢谢您的帮助.
spr*_*gle 12
编辑:看起来解决方案是使用特权容器,或手动安装您的主文件夹以允许MiniKube VM从您的hostPath读取 - https://github.com/boot2docker/boot2docker#virtualbox-guest-additions.(感谢Eliel搞清楚这一点).
绝对可以使用minikube配置hostPath卷 - 但是有很多怪癖,并且对这个特定问题没有很好的支持.
尝试ADD code/ /code从Dockerfile中删除.Docker的"ADD"指令将代码从主机复制到容器的/code目录中.这就是重建映像成功更新代码的原因.
当Kubernetes尝试将容器的/code目录挂载到主机路径时,它会发现该目录已经充满了映射到映像中的代码.如果从构建步骤中取出它,Kubernetes应该能够在运行时成功安装主机路径.
还要确保检查code/主机上目录的权限.
我唯一的其他想法与挂载在根目录中有关.我在向根目录中的目录安装Kubernetes hostPath卷时遇到问题(我假设这是与权限相关的).所以,尝试的其他东西就像mountPath一样/var/www/html.
以下是功能hostPath卷的示例:
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
volumes:
- name: example-volume
hostPath:
path: '/Users/example-user/code'
containers:
- name: example-container
image: example-image
volumeMounts:
- mountPath: '/var/www/html'
name: example-volume
Run Code Online (Sandbox Code Playgroud)
他们现在给出了minikube mount适用于所有环境的
https://github.com/kubernetes/minikube/blob/master/docs/host_folder_mount.md
在 Mac 上试过:
$ minikube mount ~/stuff/out:/mnt1/out
Mounting /Users/macuser/stuff/out into /mnt1/out on the minikube VM
This daemon process needs to stay alive for the mount to still be accessible...
ufs starting
Run Code Online (Sandbox Code Playgroud)
在豆荚中:
apiVersion: v1
kind: Pod
metadata:
name: myServer
spec:
containers:
- name: myServer
image: myImage
volumeMounts:
- mountPath: /mnt1/out
name: volume
# Just spin & wait forever
command: [ "/bin/bash", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
volumes:
- name: volume
hostPath:
path: /mnt1/out
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8325 次 |
| 最近记录: |