How do I get a file from a one-off process in Kubernetes?

5/17/2018

I have a test process which produces a file as an output.

I want to start this test process during a build, run it to completion, then collect the file that it produces and copy it back into the build context.

What is the correct way to do this in Kubernetes/Helm?

The build process has access to kubectl and helm CLI tools.

I have a requirement not to use kubectl exec, because the cluster settings do not allow it.

Some details:

I was able to configure a one-off process using a Pod.

I set up the process to store the output file in a volume mount, which is mounted to an emptyDir volume.

I cannot figure out how to get the output file.

I tried kubectl cp, but I can't get it to work (no such file or directory).

I can't figure out how to inspect the contents of a stopped container.

I can't figure out how to see what's in the volume.

kubectl logs shows that the test process ran successfully. The file is generated within the container and stored at the expected location.

Quick update:

In my local minikube environment, I was able to set up a persistent volume and copy the output file back to the host file system. I will try it next in Jenkins environment.

Here is the output from kubectl cp on my local (boot2docker) environment:

$ kubectl cp my-pod:/home/node/output . -c mycontainer
error: home/node/output no such file or directory

/home/node/output is the volumeMount path within the container.

-- RMorrisey
jenkins
jenkins-declarative-pipeline
jenkins-pipeline
kubernetes
kubernetes-helm

1 Answer

5/18/2018

I have a requirement not to use kubectl exec, because the cluster settings do not allow it.

Without the kubectl exec command, I can suggest to do it that way:

  1. Run your test as a Job inside a cluster.
  2. Use shared volume like NFS or SMB to store your file.
  3. Get files from the shared volume, which you can mount to your build system.

Also, many build systems have an Artifacts storage, and it can be the best option to store test results.

-- Anton Kostenko
Source: StackOverflow