Kubectl cp command

Sep 5, 2024·
Alfonso Fortunato
Alfonso Fortunato
· 1 min read
zettelkasten

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:

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:

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 :)

Alfonso Fortunato
Authors
DevSecOps Engineer

Hi, I’m a DevSecOps Engineer who thrives at the intersection of development, security, and operations. My journey started as a Full Stack Developer, but I quickly found my calling in the infrastructure side of things, transitioning to a DevOps/Cloud Engineer role within my first year. That shift opened the door to the world of CI/CD pipelines, Kubernetes, and cloud-native technologies, and I never looked back. Today, I focus on building secure, automated, and reproducible infrastructure. I’m a firm believer in Open Source and actively contribute to the community that shaped my career.

Never Stop Learning