How to extract a file out of a Kubernetes Job

I used my blog much as a notepad of tibits that at times I find interesting of things that I know I will use. In this post I will cover a workaround on how to extract files out of a kubernetes job.

The other day someone provided me with a new kubernetes system that they had setup. Their setup was a bit different than others that I have seen. This was an ICP based environment and they had decided that whenever they needed to run one of the cmd lines tools from HCL Commerce contained in the util container they would create kubernetes jobs. The approach works fine and there is nothing to say that they shouldn’t do it like such.

One disadvantage that I did found was that if the util creates files or requires of some files that are not in the util container image then you would have to do some setup to get the files in/out of the container.

In my case I had to get some files out of the container, time for a challenge to be resolved!.

How to get files out of the a K8S jobs

Updo doing research I found out I am not the only with this problem..go figure! :P

Bug in kubectl or feature request?

Let’s start with there is a bug/feature request for this item:

I think this is a feature request, more than a bug.


What some people had done was to create two containers in one job with a mounted volumen. The idea is that when you have a mounted volumen managed by k8s, you can then share that volumen in two containers.

The first container would use the volumen to dump the files, and then when the second container comes up you would pause the container running in the k8s job to give you time to do a kubectl cp

In practice this works like such:

Your job is defined by a .yaml file. In that .yaml file you define a volumen, and then you mount the volumen in both containers, the second container just uses the busybox image to allow you access to that volumen to extract the files.

atheiman had come up with an example here