Challenge, Medium,  on  Kubernetes

Provision Ephemeral Storage for a Pod Using a Generic Ephemeral Volume

Scenario

The analytics team needs a worker Pod that writes processed data to a storage volume.

Unlike emptyDir, which is backed by node disk by default, the team wants generic ephemeral storage: a volume that is dynamically provisioned as a PersistentVolumeClaim but still tied to the Pod lifecycle. When the Pod is deleted, the PVC and its data are automatically cleaned up.


Task

Create a Pod named analytics-worker in the analytics namespace with the following specification:

Container named worker:

  • Image: cgr.dev/chainguard/busybox:latest
  • Creates the /data directory, writes # Analytics Report to /data/index.md, then sleeps for 3600 seconds to keep the container running:
    /bin/sh -c "mkdir -p /data && echo '# Analytics Report' > /data/index.md && sleep 3600"
    
  • Mounts the ephemeral volume at /data

Generic ephemeral volume named ephemeral-storage:

  • Type: ephemeral (not emptyDir)
  • StorageClass: local-path
  • Access mode: ReadWriteOnce
  • Storage request: 1Gi

Once the Pod is running, verify the file was written:

kubectl exec analytics-worker -n analytics -c worker -- cat /data/index.md

Hint - Generic Ephemeral Volume Structure

A generic ephemeral volume is defined under spec.volumes, using the ephemeral key wrapped around a volumeClaimTemplate, the same shape a StatefulSet uses to template its per-replica PVCs:

volumes:
- name: <volume-name>
  ephemeral:
    volumeClaimTemplate:
      spec:
        accessModes:
          - <access-mode>
        storageClassName: <storage-class>
        resources:
          requests:
            storage: <storage-size>

Everything under volumeClaimTemplate.spec is the same shape as a normal PersistentVolumeClaim spec, just nested one level deeper and without its own metadata/kind. Fill in the volume name and the storage settings from the task description above, then reference that volume name from a volumeMounts entry in the worker container, the same way you'd reference any other volume.

Documentation


⚒ Test Cases