我有一个本地镜像,可以通过以下方式正常运行:
docker run -p 8080:8080 -v C:\Users\moritz\Downloads\1\imageService\examples1:/images -v C:\Users\moritz\entwicklung\projekte\imageCluster\logs:/logs imageservice
现在我想将其作为 Kubernetes 部署运行(使用 Docker-for-Windows v1.19.7 中内置的部署):
apiVersion: apps/v1
kind: Deployment
metadata:
name: image-service
spec:
selector:
matchLabels:
app: image-service
template:
metadata:
labels:
app: image-service
spec:
containers:
- name: image-service
image: "imageservice"
resources:
limits:
cpu: "0.9"
memory: "1Gi"
ports:
- name: http
containerPort: 8080
volumeMounts:
- mountPath: /images
name: image-volume
- mountPath: /logs
name: log-volume
volumes:
- name: image-volume
hostPath:
path: "c:\\Users\\moritz\\Downloads\\1\\imageService\\examples1"
type: Directory
- name: log-volume
hostPath:
path: /mnt/c/Users/moritz/entwicklung/projekte/imageCluster/logs
type: Directory
你看到我尝试了不同的方法来设置我的Windows机器上的主机路径,但我总是遇到以下问题:
Warning FailedMount 0s (x4 over 4s) kubelet MountVolume.SetUp failed for volume "log-volume" : hostPath type check failed: /mnt/c/Users/moritz/entwicklung/projekte/imageCluster/logs is not a directory
Warning FailedMount 0s (x4 over 4s) kubelet MountVolume.SetUp failed for volume "image-volume" : hostPath type check failed: c:\Users\moritz\Downloads\1\imageService\examples1 is not a directory
我还尝试了其他变量(两者都试过):
- C:\Users\moritz\entwicklung\projekte\imageCluster\logs
- C:/Users/moritz/entwicklung/projekte/imageCluster/logs
type: Directory
有助于消除错误并启动 pod,但挂载不起作用。如果我在容器中“查看”/images
,我看不到主机上的图像,而在容器中 /logs 包含了期望的文件,但日志挂载也无效。同时,我还尝试了以下方法(没有效果):
- /host_mnt/c/...
- /C/Users/...
- //C/Users/...