ETOOBUSY 🚀 minimal blogging for the impatient
Put a file in a Kubernetes Pod
TL;DR
A workaround for putting files in a Kubernetes Pod.
If you want to put a file in a Kubernetes Pod, the way to go is
usually the command kubectl cp ...
.
Alas, this requires that the target Pod has tar
installed. Which… might
not always be the case.
IF the target Pod has a working shell, though, you can use the program below, like this:
kube-put /path/to/local/file /path/inside/pod/file <kubectl exec params>
where <kubectl exec params>
will be the parameters you would normally use
to execute something in the target Pod/container, e.g. setting the
namespace with option -n
, providing the name of the Pod and optionally
providing the name of the target container with option -c
. Example:
kube-put $(which kube-put) /tmp/kube-put \
-n my-namespace pod/my-pod-name -c my-pod-container-name
Here is the program (local version here):
You MUST specify the target filename, putting the target directory is not sufficient. You are welcome to provide patches 😄
The program tries to auto-detect if base64
is installed in the target
system and, if not, use a (slow) shell-based alternative (you might have
recognized the code from A POSIX shell-only Base64 decoder). You can
force the use of the shell-base alternative by setting environment
variable USE_EMBEDDED_BASE64
to value 1
(any other value will be
ignored).
Happy transferring!