K8s不会在持久卷上挂载文件 [英] K8s doesn't mount files on Persistent Volume

查看:158
本文介绍了K8s不会在持久卷上挂载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Docker映像,我想在Kubernetes上的一个卷(一个持久卷)上共享整个目录.

I have a Docker image and I'd like to share an entire directory on a volume (a Persistent Volume) on Kubernetes.

FROM node:carbon
WORKDIR /node-test
COPY hello.md /node-test/hello.md
VOLUME /node-test
CMD ["tail", "-f", "/dev/null"]

基本上,它会复制文件hello.md并将其作为图像的一部分(我们称其为my-image).

Basically it copies a file hello.md and makes it part of the image (lets call it my-image).

在Kubernetes部署配置中,我从my-image创建一个容器,并将特定目录共享到一个卷.

On the Kubernetes deployment config I create a container from my-image and I share a specific directory to a volume.

# ...
 spec:
    containers:
    - image: my-user/my-image:v0.0.1
      name: node
      volumeMounts:
      - name: node-volume
        mountPath: /node-test
    volumes:
    - name: node-volume
      persistentVolumeClaim:
        claimName: node-volume-claim

我希望在持久卷的目录中看到hello.md文件,但是什么都没有显示.

I'd expect to see the hello.md file in the directory of the persistent volume, but nothing shows up.

如果我不将容器绑定到卷,则可以看到hello.md文件(带有kubectl exec -it my-container bash).

If I don't bind the container to a volume I can see the hello.md file (with kubectl exec -it my-container bash).

我没有做任何与此相似的事情Kubernetes官方示例.事实上,我可以更改mountPath并切换到正式的Wordpress图像,它可以按预期工作.

I'm not doing anything different from what this official Kubernetes example does. As matter of fact I can change mountPath and switch to the official Wordpress image and it works as expected.

WordPress图片如何将所有文件复制到卷目录中?

How can Wordpress image copy all files into the volume directory?

我自己缺少的Wordpress Dockerfile中有什么?

What's in the Wordpress Dockerfile that is missing on mine?

推荐答案

为了不覆盖现有文件/内容,可以使用子路径在现有Container文件系统中挂载testdir目录(在以下示例中).

In order not to overwrite the existing files/content, you can use subpath to mount the testdir directory (In the example below) in the existing Container file system.

 volumeMounts:
  - name: node-volume
    mountPath: /node-test/testdir
    subPath: testdir
volumes:
- name: node-volume
  persistentVolumeClaim:
    claimName: node-volume-claim

有关详细信息,请参见 using-subpath

you can find for more information here using-subpath

这篇关于K8s不会在持久卷上挂载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆