LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

kubectl-cp

copies files and directories between local filesystem and containers in pods

TLDR

Copy file to pod
$ kubectl cp [localfile] [pod-name]:[/path/in/container]
copy
Copy file from pod
$ kubectl cp [pod-name]:[/path/in/container] [localfile]
copy
Copy to specific container
$ kubectl cp [localfile] [pod-name]:[path] -c [container]
copy
Copy entire directory
$ kubectl cp [localdir] [pod-name]:[/remote/dir]
copy
Copy from pod in specific namespace
$ kubectl cp [namespace]/[pod-name]:[/path/in/container] [localfile]
copy
Copy without preserving permissions
$ kubectl cp [localfile] [pod-name]:[path] --no-preserve
copy

SYNOPSIS

kubectl cp src dest [options]

DESCRIPTION

kubectl cp copies files and directories between local filesystem and containers in pods. Uses tar internally, so tar must be present in the container. Supports copying in both directions.

PARAMETERS

-c, --container name

Container name in multi-container pod.
-n, --namespace name
Kubernetes namespace.
--no-preserve
Do not preserve file ownership and permissions.
--retries int
Number of retries on network errors (default: 0).

CAVEATS

Requires tar to be installed in the container. If tar is missing, the copy will fail. Large file transfers may be slow as data is streamed through the API server. Symlinks in copied directories are not followed. The namespace/pod format uses `/` as separator (e.g., `mynamespace/mypod:/path`).

SEE ALSO

Copied to clipboard
Kai