我已经创建了一个部署,我想将主机路径挂载到容器,当我检查容器时,我只看到空文件夹。
为什么我得到这个错误?原因是什么?
编辑:我用的是Windows操作系统。
apiVersion: apps/v1
kind: Deployment
metadata:
name: myservicepod6
labels:
app: servicepod
spec:
replicas: 1
selector:
matchLabels:
app: servicepod
template:
metadata:
labels:
app: servicepod
spec:
containers:
- name: php
image: php:7.2-apache
command: ["/bin/sh", "-c"]
args: ["service apache2 start; sleep infinity"]
ports:
- name: serviceport
containerPort: 80
volumeMounts:
- mountPath: /var/www/html/
name: hostvolume
volumes:
- name: hostvolume
hostPath:
path: /C/Users/utkarsh/pentesting/learnings/kubernetes/app/objectmanagement/deployments/src/*
编辑答案-
我启动minkube -minikube start --mount-string="$HOME/test/src/code/file:/data"
然后更改部署文件,如下所示
只显示音量部分
spec:
volumes:
- name: hostvolume
hostPath:
path: /C/Users/utkarsh/pentesting/learnings/kubernetes/app/deployments/src
containers:
- name: php
image: php:7.2-apache
command: ["/bin/sh", "-c"]
args: ["service apache2 start; sleep infinity"]
ports:
- name: serviceport
containerPort: 80
volumeMounts:
- name: hostvolume
mountPath: /test/src/code/file
当我登录到pod并进入目录(/test/src/code/file)时,我发现目录为空
让我知道我错过了什么?
经过详细的搜索和试验方法-找到了方法
仅适用于minikube:-
首先我们需要将主机文件夹挂载到目录名:
minikube mount src/:/var/www/html
然后我们需要定义hostPath和mountPath为
/var/www/html
因为现在我们把文件夹挂载到html文件夹
volumes:
- name: hostvolume
hostPath:
path: /var/www/html
containers:
- name: php
image: php:7.2-apache
command: ["/bin/sh", "-c"]
args: ["service apache2 start; sleep infinity"]
workingDir: /var/www/html
ports:
- name: serviceport
containerPort: 80
volumeMounts:
- name: hostvolume
mountPath: /var/www/html