DEV Community

Parikshit Chavan
Parikshit Chavan

Posted on

1

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay