1
  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace
<some-namespace>
  kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar

works, but then a pod should be running. The problem is that the file has to be copied before the pod starts. The jar file has to be loaded by an Application server. Destroying the pod after the copy will not work as the docker image is deployed again and the content will be wiped out.

A configMap was misused to copy the jar before the pod starts, but that only seems to work for configuration files. This was confirmed by comparing the checksum, e.g. local vs. remote.

3
  • You're more or less asking to load memory into a process namespaces before the process exists, I.e placing a couch in a house before the house is built... I don't see a solution there
    – Tensibai
    Mar 1 '18 at 22:57
  • Copying config using configMap works, but if a larger file, like a jar needs to be copied then it is better to bake it using a Dockerfile?
    – 030
    Mar 1 '18 at 23:07
  • 1
    In brief Config Maps are files rendered on the target node for the pod from etcd and then the container is launched with this mount. I don't think it's a viable way for large files like a jar.
    – Tensibai
    Mar 2 '18 at 6:38
4

Ok. Maybe you're not gonna like it but there are some things you can do.

One and most simple is to use a volume mount, eventually on a persistent storage but I think an emptyDir can work as well (or even better depending on the nature of the file you want to copy) and use an init container to copy the file to the volume before the app container start. I don't know how you generate that file and I can't speculate about the security implications but the file needs to be in the docker image used for the init container. So, for your init container, you will have a Docker file like

FROM ubuntu
COPY localfile /container/file
CMD cp /container/file /mnt/kube-volume

replacing localfile, container/file and /mnt/kube-volume with appropriate values; you build the container image locally -on your machine, so it can contain the file- and upload it to the (secure) docker repo along with the app container image.

Another method is to upload the file to a (secure) location and have an init container or a bootstrap process that download the file when you start your main application container in the pod.

The third option is to create a docker image that contains that file and use it for the app container in your pod.

0

If it's a small(<1MB) file, you can create a configmap with "--from-file" and mount it into volume.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.