debug

kubectl cp

Copies files and directories between your local filesystem and a container in a pod. Uses tar under the hood, so the target container must have a working tar binary on its PATH.

kubectl cp <src> <dst> [-c CONTAINER] where src/dst may be POD:PATH

Common flags

Flag Purpose
-c, --container Container inside a multi-container pod.
-n, --namespace Namespace of the pod (or use ns/pod:path form).
--retries Number of retry attempts on transient failure (default 0).
--no-preserve Do not preserve file mode/ownership on the destination.

Examples

kubectl cp ./local.conf web-abc:/etc/app/local.conf

Push a file from your machine into the pod.

kubectl cp web-abc:/var/log/app.log ./app.log

Pull a log file out of the pod.

kubectl cp ./dir web-abc:/tmp/dir -c sidecar

Copy a directory into a specific sidecar container.

Gotcha

Fails silently on distroless/scratch images that lack tar. Absolute paths on Windows may need quoting to avoid drive-letter confusion.

Related commands

← All kubectl commands · Docker vs Kubernetes