Kubernetes PVC删除POD的内容 [英] Kubernetes PVC deleting the contents of the POD

查看:262
本文介绍了Kubernetes PVC删除POD的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Kubernetes POD,并且已在其中附加了PVC. PVC卷为/opt/stackstorm.

I have a Kubernetes POD running and I have attached a PVC to it. The PVC volume is /opt/stackstorm.

默认情况下,/opt/stackstorm中有某些文件,这些文件是docker官方映像的一部分.当没有PVC附加到POD时,这些文件是可见的.

By default, there are certain files inside the /opt/stackstorm which comes as part of the docker official image. These files are visible when there is no PVC attached to the POD.

但是,当连接PVC时,将替换文件并创建一个丢失和找到的目录.

But when a PVC is attached, the files are replace and a lost&found directory is created.

即使附上PVC,我们如何仍可以保留目录?

How we can retain the directory even after attaching the PVC ?

我已经更改了PVC的目录.当我将目录从opt/stackstorm更改为/opt/stack时,/opt/stackstorm拥有所有详细信息,但/opt/stack变为空.

I have changed directories for the PVC. When I change the directory from opt/stackstorm to /opt/stack then /opt/stackstorm has all the details but /opt/stack becomes empty.

因此,将PVC附加到POD时会产生问题.

So the PVC when attached to a POD is creating issue.

pvc.yaml:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: stacke
  annotations:
    volume.beta.kubernetes.io/storage-class: "ebs"
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

deployment.yaml:

       volumeMounts:
          - name: stacke
            mountPath: /opt/stackstorm
      volumes:
      - name: stacke
        persistentVolumeClaim:
          claimName: stacke
      imagePullSecrets:
      - name: regcred

预期结果是/opt/stackstorm应该将所有文件作为映像的一部分.

expected results is that /opt/stackstorm should have all the files as part of the image.

推荐答案

,您可以将/opt/stackstorm的内容复制到dockerfile中的新目录并构建新映像.之后,您可以在运行时将新目录的内容复制回/opt/stackstorm.发生所有此问题是因为在构建时初始化了该目录. 要在运行时进行复制,您可以在以下容器的生命周期中使用 postStart kubernetes. 例如: spec: containers: - name: .... image: .... lifecycle: postStart: exec: command: ["cp" , "-r" , "/test/" ,"/opt/stackstorm"] 此命令在容器启动后运行. 但是这种方法每次pod启动时都会复制一次,如果要避免这种情况,可以在构建时删除dockerfile中/opt/stackstorm的内容,然后在postStart命令中编写脚本以检查该目录是否为空,以进行复制. 而且,您可以将/opt/stackstorm作为mountPath并将pvc附加到其上,就像完成操作一样.

you can copy the the content of /opt/stackstorm to a new directory in dockerfile and build a new image . After that you can copy the content of the new directory back to /opt/stackstorm in run time. All of this issue occurred because this directory get initialized in build time . For copying in run time you can use postStart in container lifecycle in kubernetes . for example : spec: containers: - name: .... image: .... lifecycle: postStart: exec: command: ["cp" , "-r" , "/test/" ,"/opt/stackstorm"] this command run after the container start . but this approach copy every time the pod start , if you want to avoid this you can delete the content of the /opt/stackstorm in dockerfile in build time and then in postStart command write the script to check if this dir is empty do copying . And you can have /opt/stackstorm as mountPath and attach a pvc to it just like you have done.

这篇关于Kubernetes PVC删除POD的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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