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.