我正在尝试在 Kubernetes 中构建一个 Pod,使该 Pod 中的文件可以从我的本地系统挂载到 Pod 中,类似于在
我已经尝试了以下内容,试图将本地文件夹
docker-compose
文件中挂载卷的方式。我已经尝试了以下内容,试图将本地文件夹
./test
和文件挂载到位于/blah/
文件夹下的 Pod 中。但是 Kubernetes 正在抱怨:MountVolume.SetUp failed for volume "config-volume" : hostPath type check failed: ./test/ is not a directory
以下是我的 yaml
文件。我是否漏掉了什么?kind: Service
metadata:
name: vol-test
labels:
app: vol-test
spec:
type: NodePort
ports:
- port: 8200
nodePort: 30008
selector:
app: vol-test
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: vol-test
spec:
replicas: 1
selector:
matchLabels:
app: vol-test
template:
metadata:
labels:
app: vol-test
spec:
containers:
- name: vol-test
image: nginx
imagePullPolicy: "IfNotPresent"
volumeMounts:
- name: config-volume
mountPath: /blah/
ports:
- containerPort: 8200
volumes:
- name: config-volume
hostPath:
path: ./test/
type: Directory
path:
相对于哪个目录进行解释?你将如何将源代码复制到集群中的每个节点?(这不是 Kubernetes 模式,出于类似的原因,我会不鼓励它作为 Docker 模式。) - David Maze./test
是相对于我运行 kubectl apply 的目录的。这是一个用于测试的 pod,只会有一个实例。 - Colonel Mustard