简体   繁体   English

定期从 Kubernetes Pod 中的 Volume Mount 中删除文件

[英]Remove files periodically from Volume Mount in Kubernetes Pod

I have a kubernetes pod running which has two containers, say A and B. They share common volume of type emptyDir .我有一个 kubernetes pod 正在运行,它有两个容器,比如说 A 和 B。它们共享类型emptyDir公共卷。 I have a usecase in which application running in container A takes files uploaded by client and places them at mount point.我有一个用例,其中在容器 A 中运行的应用程序获取客户端上传的文件并将它们放置在安装点。 Then it signals to container B to process the file.然后它向容器 B 发出信号以处理该文件。 Container B then sends back response to A (The response is instantaneous and not batched).然后容器 B 向 A 发回响应(响应是即时的,不是批处理的)。 Now as the file is processed it can be deleted (It must be, due to obvious storage constraints).现在当文件被处理时,它可以被删除(它必须是,由于明显的存储限制)。 Deleting files one by one as they are processed could be lot of deletions (or not?) so thought of considering batch deletions periodically.在处理文件时一个一个地删除文件可能是大量删除(或不是?),因此考虑定期考虑批量删除。

  1. What is the best way to delete this file?删除此文件的最佳方法是什么?
  2. Is it good to use this volume type for this usecase?将此卷类型用于此用例是否好? If not what?如果不是什么?
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: FileProcessor
  labels:
    app: FileProcessor
spec:
  selector:
    matchLabels:
      app: FileProcessor
  template:
    metadata:
      labels:
        app: FileProcessor
    spec:
      containers:
      - image: processor:0.2
        name: Container_B
        ports:
        - containerPort: 80
          name: Container_B
        volumeMounts:
        - name: upload-files
          mountPath: /app/upload-files
      - image: sample:0.1
        name: Container_A
        ports:
        - containerPort: 8000
          name: Container_A
        volumeMounts:
        - name: upload-files
          mountPath: /app/uploads
      volumes:
      - name: upload-files
        emptyDir: {}

PS: This is to be deployed on GKE. PS:这将部署在 GKE 上。 Update 1: Still looking for a better solution更新 1:仍在寻找更好的解决方案

As you are using emptyDir , files must be deleted from one of the sidecars.当您使用emptyDir ,必须从 sidecar 之一中删除文件。 Now, lets check what are your options here:现在,让我们检查一下您的选择:

  1. Container A or B can delete the files after processing them.容器 A 或 B 可以在处理后删除文件。
  2. Container A or B delete the files once they reach a certain amount (say 1Gi).一旦文件达到一定数量(比如 1Gi),容器 A 或 B 就会删除文件。
  3. Add another container C which periodically cleanup the files.添加另一个定期清理文件的容器 C。

Now, lets check advantage and disadvantage of these solutions:现在,让我们检查一下这些解决方案的优缺点:

  • If you go with solution 1, your container A or B will have to do little extra work after each processing.如果您采用解决方案 1,则您的容器 A 或 B 在每次处理后将不得不做一些额外的工作。 If the files size are not large enough this extra time shouldn't be significant如果文件大小不够大,这个额外的时间应该不会很重要

  • If you go with solution 2, you might save extra work after each processing.如果您使用解决方案 2,您可能会在每次处理后节省额外的工作。 However, after a certain period container A or B will require a relatively long time to cleanup those files.但是,经过一段时间后,容器 A 或 B 将需要相对较长的时间来清理这些文件。 Furthermore, you have to add logic when to cleanup the files.此外,您必须添加何时清理文件的逻辑。 If you can do it intelligently, let say when your containers are idle, then this solution should fit best.如果你能聪明地做到这一点,比如说当你的容器空闲时,那么这个解决方案应该是最合适的。

  • Now, if you go with solution 3, you have to ensure that your container C does not delete files that are being processed by container B.现在,如果您采用解决方案 3,则必须确保容器 C 不会删除容器 B 正在处理的文件。

In case, you want to use a different type of volume, which can be mounted from an external pod, then you can have a CronJob to periodically cleanup those data.如果您想使用不同类型的卷,可以从外部 pod 挂载,那么您可以使用 CronJob 定期清理这些数据。 In this case, same constraint of solution 3 is applicable.在这种情况下,解决方案 3 的相同约束也适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Kubernetes中将卷安装到Pod - How to mount a volume to a pod in Kubernetes kubernetes:在pod启动后挂载主机路径卷 - kubernetes: Mount hostpath volume after pod start 在Kubernetes中保持Pod Volume Mount的可配置性 - Keeping pod volume mount configurable in Kubernetes 使用kubernetes pod中的服务帐户从NFS挂载访问文件 - Access files from NFS mount with service account in kubernetes pod Kubernetes 卷装载 ConfigMap 到 pod 内的文件,而不覆盖所有其他文件 - Kubernetes Volume Mount ConfigMap to File within the pod without overwriting all other files 如何从使用 KubernetesPodOperator 触发它的 Airflow 主机将卷挂载到运行 docker 容器的 Kubernetes Pod - How to mount a volume to a Kubernetes Pod running a docker container from the Airflow host that triggers it using the KubernetesPodOperator 无法将Amazon Web Services(AWS)EBS卷安装到Kubernetes pod中 - Unable to mount Amazon Web Services (AWS) EBS Volume into Kubernetes pod Amazon EKS (NFS) 到 Kubernetes pod。 无法挂载卷 - Amazon EKS (NFS) to Kubernetes pod. Can't mount volume 无法使用 Azure 文件配置器将卷安装到 Kubernetes 中的 pod - Cannot mount volume to pod in Kubernetes using Azure file provisioner 为什么GCE卷安装在kubernetes容器中会导致延迟? - Why does a GCE volume mount in a kubernetes pod cause a delay?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM