Question

How to access ephemeral block storage in Kubernates jobs

I have Kubernates jobs which each require ~300GB of temporary disk space whilst they are running, then send files to an external service when done.

Currently I’m using DigitalOcean managed Kubernates with their storage optmised Droplets. However this is much more expensive than using Droplets with less vCPU but atatched block storage.

These jobs are automated (run by a Python script). DigitalOcean’s support article talks about creating a StatefulSet but I don’t understand how to do this at each jobs runtime, or if this is the right approach.

So how would you reccomend the following? Running Kubernates jobs which each require ~300GB of temp space but relatively low vCPU and Memory.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there @d825171ca273f05,

What I would do in this case is to also use a block storage and a PVC. That way you could attach the storage to a specific deployment and use it as a volume just like you would with a standard Droplet.

So rather than a StatefulSet you could use a standard Kubernetes deployment, for example:

  • First create the PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: your-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: do-block-storage
  • Then attach the volume to your pods:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: your_app
spec:
  selector:
    matchLabels:
      app: your_app
  template:
    metadata:
      labels:
        app: your_app
    spec:
      containers:
      - name: your_app
        image: your_image:latest
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: "/var/lib/your_path"
          name: do-block-storage
      volumes:
        - name: do-block-storage
          persistentVolumeClaim:
            claimName: your-pvc

Here is a similar discussion here:

https://www.digitalocean.com/community/questions/how-to-use-digital-ocean-volumes-as-persistent-storage-for-the-pod-to-share-the-storage-across-multiple-pods

The main thing that you need to keep in mind is that the volume can be attached as ReadWriteOnce meaning that it would only be available on one node. So in case that you need to use multiple pods, they all need to be scheduled on the same node.

Hope that this helps! Regards, Bobby