← Back to blog

How to Copy Files From a PVC to Your Machine (and Back)

November 20, 2026
How to Copy Files From a PVC to Your Machine (and Back)

A PersistentVolumeClaim (PVC) is not a folder you can open directly. To copy files from one, you reach it through a pod that mounts the claim, then pull the files out with kubectl cp or a tar stream over kubectl exec. If no running pod mounts the claim, or the image has no tar, you start a small helper pod that does. This guide gives each route, the commands, and the points where they break.

If you do this often across several clusters, the friction is rarely the copy command. It is finding the right pod, namespace and mount path each time. Our desktop app, Kubezilla Desktop, includes PVC file browsing next to pod terminals and multi-cluster access, so you can inspect a volume without assembling commands first.

Kubezilla Desktop
kubezilladesktop.com
Browse PVC Files Alongside Your Pods
Kubezilla Desktop brings PVC file browsing together with pod terminals and multi-cluster access, helping you inspect volumes without assembling commands first.
Visit

TL;DR

  • A PVC is reached through a pod that mounts it: find that pod, find the mount path, then run kubectl cp <namespace>/<pod>:<path> <local-path>.
  • kubectl cp needs the tar binary inside the container, so it fails on distroless and many minimal images.
  • To upload into a PVC with no running workload, create a short-lived BusyBox pod that mounts the claim and stream files in with a tar pipe.
  • For large volumes or restricted images, use a helper pod with a purpose-built tool or a tar stream over kubectl exec.
  • Most failures come from three causes: missing tar, write permissions, and a ReadWriteOnce volume already attached to another node.

Table of Contents

Step 1: Find the pod and mount path for the PVC

Pods use storage by listing a persistentVolumeClaim in their volumes block; the cluster finds the bound volume and mounts it for the pod. So the files are visible at whatever mountPath the container declares.

There is no single command that says which pod uses a PVC. A jsonpath query over pods can map pods to claims. A more readable route:

kubectl get pods -n <namespace> -o yaml | grep -B5 -A2 claimName
kubectl describe pod <pod> -n <namespace>

In the describe output, look at Mounts: for the container path and Volumes: for the claim name. Then confirm what is mounted and how full it is:

kubectl exec -n <namespace> <pod> -- df -h /data
kubectl exec -n <namespace> <pod> -- ls -la /data

This is the workflow used in a widely cited 2019 walkthrough: find the mount path, inspect with ls and df, then copy.

The manual part is repetitive when you have many namespaces. In Kubezilla Desktop you can browse a PVC's files from the same window where you open pod terminals, which removes the lookup loop for the common case.

Step 2: Copy files out with kubectl cp

The kubectl cp reference describes it as copying files and directories to and from containers. Syntax:

# PVC path to local
kubectl cp <namespace>/<pod>:/data/dump.rdb ./dump.rdb

# a whole directory
kubectl cp <namespace>/<pod>:/data ./data-backup

# a specific container in a multi-container pod
kubectl cp -c <container> <namespace>/<pod>:/data ./data-backup

Things to know:

  • The namespace goes in the prefix as <namespace>/<pod>.
  • -c selects a container. Without it, the default-container annotation or the first container is used.
  • --no-preserve skips preserving ownership and permissions.
  • --retries defaults to 0, so a dropped connection fails the copy. Set a positive value, or a negative one to retry indefinitely, on flaky links.

Under the hood, kubectl cp has no file-transfer API. It shells out to tar in the container and streams the archive. That explains nearly every failure below.

Check the copy

Compare file counts and sizes after copying:

kubectl exec -n <namespace> <pod> -- sh -c 'find /data -type f | wc -l'
find ./data-backup -type f | wc -l

The Kubernetes reference itself recommends kubectl exec rather than cp when you need symlinks, wildcard expansion or file-mode preservation.

Step 3: Copy files into a PVC

Copying in works the same way in reverse:

kubectl cp ./config.yaml <namespace>/<pod>:/data/config.yaml

The files persist because the path is backed by the claim, not the container's own filesystem. One caveat: ownership is not preserved. Uploaded files belong to the container's user, for example uid 1000 when the pod sets runAsUser: 1000. If your application runs as a different user, fix ownership afterward with chown through kubectl exec.

When no pod mounts the claim

A claim that nothing uses cannot be copied into. Create a throwaway pod that mounts it. The pattern in the NVIDIA NeMo Framework docs is a BusyBox container running sleep infinity with the claim mounted:

apiVersion: v1
kind: Pod
metadata:
  name: pvc-helper
spec:
  containers:
  - name: helper
    image: busybox
    command: ["sleep", "infinity"]
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: <your-claim>

Apply it, then stream files in with tar over exec. The same docs note that exec has fewer surprises than kubectl cp with compressed files:

tar cf - ./local-dir | kubectl exec -i -n <namespace> pvc-helper -- tar xf - -C /data

When no pod mounts the claim

When you are done, delete the pod. It uses very little while idle, but it also holds the claim, which matters in the next section.

Step 4: Fix the common failures

SymptomCauseFix
exec: "tar": executable file not found or exit code 126The image has no tarVerify with tar --version, then use a helper pod or exec with cat
permission deniedContainer user cannot write to the path, or the filesystem is read-onlyCopy to /tmp first, or adjust the target folder's permissions where policy allows
unexpected EOFPod restarted mid-copy, or a long transfer droppedRetry, compress, use --retries
Symlinks missingcp does not follow themUse tar -h through exec
Helper pod stuck PendingVolume already attached elsewhereSee the ReadWriteOnce note below

The last two rows and the permission advice follow a troubleshooting table of common failure modes and a kubectl cp guide that recommends staging in /tmp, which also notes production pods may block permission changes by design.

Missing tar and distroless images

Distroless images have no tar and no package manager, so you cannot install it at runtime. The workaround is an ephemeral debug container that carries tar. It needs the SYS_PTRACE capability to reach the target's root filesystem through /proc/1/root, which the default general profile adds but baseline and legacy do not. We cover the mechanics in our guide to Kubernetes ephemeral containers.

For a single small text file without tar, you can stream it:

cat ./config.yaml | kubectl exec -i <pod> -- sh -c "cat > /tmp/config.yaml"

RBAC

Copying needs permission to get, list and exec pods in the namespace, because it rides on an exec session. If cp returns forbidden errors, ask your cluster admin for pods/exec in that namespace.

ReadWriteOnce volumes

A claim backed by a ReadWriteOnce disk can be mounted read-write by only one node at a time. If the application pod runs on node A, your helper pod may be scheduled on node B and hang. Either set nodeName or affinity on the helper to match the application pod's node, or scale the workload down first. If you need to scale, see our deployment scaling commands.

Step 5: Large volumes and repeatable transfers

Plain kubectl cp and exec degrade for very large transfers, around 100Gi in one example, and need tar in the image. For those cases the usual patterns are:

  • A helper pod with an SFTP-style transfer tool. One open-source plugin runs a temporary pod that mounts the PVC, supports concurrent transfers with SHA-256 checks, and cleans up afterward.
  • Compressed tar over exec. tar czf - /data | ... reduces bytes on slow links.
  • Jobs or init containers for repeatable loading in deployments. On managed platforms such as GKE, file placement is a workload concern handled by Jobs or init containers, not manual copying.
  • Virtual machine disks. For KubeVirt-style disk images, virtctl image-upload uploads to a PVC that must be larger than the uncompressed image.

Migrating data between claims

For moving data to a new PVC, a documented pattern is to stop the app pod, run a temporary Ubuntu pod with the old claim at /mnt, copy out to a local folder, re-point the pod's claimName to the new claim, and copy back in. It works when the application image lacks tar, as with MinIO.

PVC migration from old claim to new

A note on sizes and paths

Two details save confusion. A 10Gi volume typically shows about 9.8G in df because ext4 reserves space for metadata. And if you mount only a subdirectory, use subPath under volumeMounts. Databases such as MySQL can refuse to start if they find lost+found in the data directory, and subPath avoids that.

Where Kubezilla Desktop fits

Every step above is command assembly: namespace, pod, container, path, then a fix when tar or permissions fail. Kubezilla Desktop is a native app for Linux, macOS and Windows that puts PVC file browsing, pod terminals, live logs and YAML editing in one interface, with multi-cluster access and SSH tunnels. Your kubeconfigs are stored securely on your machine, and the app has no cloud sync or telemetry. It costs 5 EUR per month, and you can see the app and its features here.

Kubezilla Desktop

If your clusters sit behind a bastion, our guide to SSH tunnels for Kubernetes shows how the connection is made, and the same tunnels carry file browsing. For checking what a pod is doing while you copy, see viewing Kubernetes logs.

Our perspective

Copying a file out of a volume should take seconds. In practice, engineers spend the time on everything around it: which context, which namespace, which pod holds the claim, which container has tar.

We built Kubezilla Desktop in Rust as a native app because that lookup work belongs in an interface, not in your shell history. Browsing a PVC next to a pod terminal, with every cluster in one place and kubeconfigs kept locally, means the copy is the last step instead of the fifth.

Commands stay useful for scripts and pipelines. For the interactive, one-off work of getting a file out of a volume, we think a fast, lightweight desktop client is the better tool.

Margus

FAQ

Can I copy files from a PVC without a running pod?

Not directly, because a PVC is only reachable through a pod that mounts it. Create a short-lived helper pod, such as BusyBox running sleep infinity, that mounts the claim, copy the files, then delete the pod.

Why does kubectl cp say tar is not found?

kubectl cp runs tar inside the container, so images without it, including distroless ones, fail. Use a helper pod that mounts the same claim, or an ephemeral debug container that includes tar.

How do I copy a whole directory from a PVC?

Point kubectl cp at the directory path, for example kubectl cp <namespace>/<pod>:/data ./backup. It copies recursively. For symlinks or exact file modes, use kubectl exec with a tar stream instead.

Why is my helper pod stuck in Pending?

The claim is probably ReadWriteOnce and attached to a different node than the one your helper was scheduled on. Place the helper on the same node as the application pod, or scale the application down first.

Sources