← 返回命令列表

Linux command

kubectl-cp 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Copy file to pod

kubectl cp [localfile] [pod-name]:[/path/in/container]

Copy file from pod

kubectl cp [pod-name]:[/path/in/container] [localfile]

Copy to specific container

kubectl cp [localfile] [pod-name]:[path] -c [container]

Copy entire directory

kubectl cp [localdir] [pod-name]:[/remote/dir]

Copy from pod in specific namespace

kubectl cp [namespace]/[pod-name]:[/path/in/container] [localfile]

Copy without preserving permissions

kubectl cp [localfile] [pod-name]:[path] --no-preserve

说明

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.

参数

-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).

FAQ

What is the kubectl-cp command used for?

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.

How do I run a basic kubectl-cp example?

Run `kubectl cp [localfile] [pod-name]:[/path/in/container]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --container _name_ do in kubectl-cp?

Container name in multi-container pod.