kubernetes 目录复制到minikube,但不复制到其中的文件

5anewei6  于 2023-06-21  发布在  Kubernetes
关注(0)|答案(1)|浏览(158)

这是主机上的目录:

├── deploy.yaml
└── foobar
    └── foo.sh

和deploy.yaml文件的内容:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: foobar-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foobar-app
  template:
    metadata:
      labels:
        app: foobar-app
    spec:
      containers:
        - name: foobar-container
          image: nginx
          #command: ["sh", "-c", ""/foobar/foo.sh""] 
          volumeMounts:
            - name: foobar-volume
              mountPath: /foobar
      volumes:
        - name: foobar-volume
          hostPath:
            path: /home/n/projects/minikube-test/foobar

当我执行到容器中时,我看到foobar目录,但不是foo.sh。

k exec -it foobar-deployment-8459bf6d8f-mlprq -- ls -lart foobar
total 8
drwxr-xr-x 2 root root 4096 Jun 17 02:37 .
drwxr-xr-x 1 root root 4096 Jun 17 03:14 ..

我错过了什么?谢谢你

doinxwow

doinxwow1#

这样做奏效了:首先,将主机目录装载到VM上的某个位置:

minikube mount /home/n/projects/minikube-test/foobar:/mnt1/foobar

接下来,修改deploy.yaml文件:

volumeMounts:
            - name: foobar-volume
              mountPath: /foobar
      volumes:
        - name: foobar-volume
          hostPath:
            path: /mnt1/foobar

相关问题