Copy files and directories from and to Kubernetes pods

At work we have a project that uses node:10-jessie image as a base for its docker container. That image has no vi inside so I wondered how to check the content of a file. Luckily kubectl has a neat command to copy files from and to a pod.

It's basically:

> kubectl cp <namespace>/<pod name>:/path/to/file.js ~/Desktop/file.js

To get the available namespaces use:

> kubectl get ns

(Here you should make sure that your kubectl points to the right context).

And to get the available pods:

> kubectl get pods

Copying a file from your local machine to the pod happens the same way. Just flip the arguments. Of course that file wouldn't be there if the pod dies and gets replaced with another one.

If you enjoy this post, share it on Twitter, Facebook or LinkedIn.

With over two decades of deep front-end expertise, I offer comprehensive web consultancy and stack audits, alongside specialized workshops, training, and engaging public speaking to elevate your team's skills and optimize your digital presence. Contact me.