Life's random bits By b1thunt3r (aka Ishan Jain)…
Copy files between Kubernetes Pods and Local Machine

Copy files between Kubernetes Pods and Local Machine

Ishan jain
A pod in Kubernetes is not a total black box, we can copy files.

There are time we would like to copy files from a pod to our local machine, or inject file from local machine to pod.

kubectl cp <source> [<namespace>/]<pod>:<destination>
kubectl cp [<namespace>/]<pod>:<source> <destination>

# alternatively
kubectl cp -namespace <namespace> <pod>:<source> <destination>
kubectl cp -namespace <namespace> <source> <pod>:<destination>

Where:

  • namespace: optional namespace name
  • pod: pod name
  • source: source absolute path to file or directory
  • destination: destination absolute path to file or directory

For example, following command will copy /etc/nginx/nginx.conf on nginx pod to /tmp/nginx.conf on local machine:

kubectl cp nginx:/etc/nginx/nginx.conf /tmp/nginx.conf

Resources