写入卷装载时 Kubernetes pod 运行 内存不足

Kubernetes pod running out of memory when writing to a volume mount

我有一个 Kubernetes 集群,需要处理作业。这些职位定义如下:

apiVersion: batch/v1
kind: Job
metadata:
  name: process-item-014
  labels:
    jobgroup: JOB_XXX
spec:
  template:
    metadata:
      name: JOB_XXX
      labels:
        jobgroup: JOB_XXX
    spec:
      restartPolicy: OnFailure
      containers:
      - name: worker
        image: gcr.io/.../worker
        volumeMounts: 
        - mountPath: /workspace
          name: workspace
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 512Mi  
      volumes: 
        - name: workspace 
          hostPath:
            path: /tmp/client-workspace

请注意,我正在尝试将主机中的文件夹装载到容器中 (workspace)。还要注意定义的内存限制。 在我的容器上,我将一些文件下载到 workspace,其中一些文件非常大(它们是使用 gsutil 从 GCS 下载的,但不要认为这太重要)。

当我下载的文件超出内存限制时,我的代码会中断并出现 "device out of space" 错误。这并不完全有意义,因为我将文件存储到一个挂载中,该挂载由主机的存储支持,这绰绰有余。 docs 中还提到,memory 限制的是容器可用的 RAM 数量,而不是存储空间。不过,当我将限制设置为 XGi 时,它会在 XGi 下载后非常一致地中断。

我的容器基于 ubuntu:14.04,运行 一个 shell 脚本,其中一行如下:

gsutil -m cp -r gs://some/cloud/location/*  /workspace/files

我做错了什么?我的容器肯定需要有一些限制,所以我不能放弃限制。

/tmp 文件系统通常由 tmpfs, which stores files in memory rather than on disk. My guess is that is the case on your nodes, and the memory is being correctly charged to the container. Can you use an emptydir 卷支持?