Data Explorer for PersistentVolumeClaim of a Cronjob [hack]

We have some Kubernetes cronjobs configured with a PVC (PersistentVolumeClaim), and during an upgrade of the cronjob, we needed to access the data it was using so we could clean some stuff. When your application is deployed using a Kubernetes Deployment resource is pretty straight forward, the pods are continuously running, and if you don’t use a scratch base image, you most of the time have access to some shell.

When you are using a standard deployment is very easy to access the mounted PVC by using

kubectl exec -ti somepod bash.

Unfortunately, we don’t have this possibility when we have CronJob resources since they tend to be more shortlived and start only at specific intervals. So I looked for an alternative solution ๐Ÿ˜›

The (Hacky) Solution

I came up with a straightforward deployment, which we could scale up once we need to examine the data โ€” acting as a proxy to PVC.

The only problem I encounter was I need to have a command which would keep the pods running. Luckily I learned that the sleep command accepts infinity as duration parameter ๐Ÿ˜…

So once you apply the deployment, you can access a shell using kubectl exec -ti explorer-... bash and examine or alter your data.

An example deployment

---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: explorer
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: explorer
    spec:
      containers:
        - name: explorer
          image: debian
          command: ["sleep", "infinity"]
          volumeMounts:
            - name: data
              mountPath: /data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: data