Working noteSep 5, 2024

Kubectl cp command

Handy kubectl command to copy container content between pods

Cover graphic for Kubectl cp command

Kubernetes troubleshooting tales

While debugging a tough problem with buildkit-rootless mode for building a Docker image on a pod provisioned via the Jenkins Kubernetes Plugin, I discovered a handy Kubernetes command to copy the contents of a specific container pod to another pod.

Copy the content of a problematic pod to a local directory:

bash
kubectl cp <pod_name>:<path_of_container_want_to_copy> <local_path> -c <specific_container>

Then, copy the local content to the fresh pod, for example, into the /tmp directory:

bash
kubectl cp <local_path> <new_pod>:/tmp

You can run your problematic command in a fresh pod through exec, see if the error persists, and debug from there.

PS: Still figuring out why a rootless pod with buildkit doesn't work when provisioned via Jenkins (even though it has the same specs as the fresh one). Perhaps this will be another Kubernetes troubleshooting tale :)

↗ Open for work

Need the person
who ships it?

I'm looking for platform engineering and DevSecOps roles in regulated, product or cloud native teams. Kubernetes, supply-chain security and self-service platforms are the core. Also open to select technical writing and open-source collaborations.

Work with me See the experience
← All notes

Search the site

esc

Jump to

    ↑↓ to navigate ↵ to open esc to close