DEV Community

Parikshit Chavan
Parikshit Chavan

Posted on

Copying local file/directory to the k8s pod

When there comes a scenario when you have to copy any file or directory to the kubernetes pod, make it available for the application. Lets say, you have a folder that have videos that you want to make available in the pod.

Let's see a simple way to it.

let me show you my current pod where i want to upload a directory.

use

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Output:

Listing out our pods

here, you can see the app1-fdc77f597-nn598 pod, where we will upload a file.

Use this command to exec inside the pod,

kubectl exec -it app1-fdc77f597-nn598 -- /bin/sh

I will be copying my videos folder from the host machine to this pod directory.

lets copy this pod directory, which we will use later,
use pwd
/app is the pod-path

Lets exit from the pod and look what we have in the host machine.

[parikshit@parikshit videos]$ ls
sample-vid-1.mp4  sample-vid-2.mp4

Enter fullscreen mode Exit fullscreen mode

i have these videos that needs to be uploaded.
let take the local-path, by using pwd command

[parikshit@parikshit videos]$ pwd
/home/parikshit/folder1/videos

Enter fullscreen mode Exit fullscreen mode

this is our loacl-path

Now lets copy to our pod

we will be using following command
kubectl cp <local-path> <pod-name>:<pod-path>

so our command will be

kubectl cp /home/parikshit/folder1/videos app1-fdc77f597-nn598:/app

After it gets executed, just get inside our pod, and check our /app/videos/ directory.

kubectl exec -it app1-fdc77f597-nn598 -- /bin/sh

Image description

And we see all our videos inside the pod.

Like and share the post, if it was helpful.
Happy Coding ! :)

Top comments (0)