Copy Files in Kubernetes with ‘Kubectl CP’

A Beginner’s Guide

Arton Demaku

Managing files inside your containers that are inside of a pod in a Kubernetes cluster can be a bit of a puzzle. But fear not! There’s a nifty tool called ‘Kubectl CP’ that makes copying files to and from Kubernetes containers a breeze. In this beginner-friendly guide, we’ll walk you through the ins and outs of using ‘Kubectl CP’ to streamline your file management.

What is ‘Kubectl CP’?

Imagine you have a Kubernetes pod, and you need to transfer files to or from it. ‘Kubectl CP’ is your trusty sidekick for this task. It’s like the familiar ‘SCP’ command in the Linux world, but tailored specifically for Kubernetes.

Basic Usage

To copy files to and from a Kubernetes container, you only need a couple of straightforward commands:

Copying from a container to your local machine:

kubectl cp <namespace>/<pod-name>:<path-to-file-in-pod> <local-destination>

For example, if you have a file /tmp/foo in a pod named my-pod in the my-namespace namespace and want to copy it to your local machine's /tmp/bar, the command would be:

kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Arton Demaku

DevOps Engineer with experience in AWS, GCP, Jenkins, Docker, Kubernetes. Passionate about automation and committed to delivering secure and reliable systems.