Copy files and directories from and to Kubernetes pods

Blog / Architecture ·

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.


Krasimir Tsonev With over two decades of deep programming 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.

Keywords: Kubernetes copy pods ssh
Share the post on Twitter, Facebook, LinkedIn