[kubernetes]-k8s从指定container中cp文件
普通单container的podkubectl cp 命名空间/容器名:/容器目录/文件名 /宿主机目录/文件名多container的podkubectl cp容器名:/容器目录/文件名-c 指定的container名 /宿主机目录/文件名 -n 命名空间# 从namespace为test pod名称为servicecenter-dp-0,其中container名称为servicecenter中c
·
普通单container的pod
kubectl cp 命名空间/容器名:/容器目录/文件名 /宿主机目录/文件名
多container的pod
kubectl cp 容器名:/容器目录/文件名 -c 指定的container名 /宿主机目录/文件名 -n 命名空间
# 从namespace为test pod名称为servicecenter-dp-0,其中container名称为servicecenter中cp jar包
kubectl cp servicecenter-dp-0:/srv/servicecenter/ihaozhuo-servicecenter-6.0.1-SNAPSHOT.jar -c servicecenter /tmp/ihaozhuo-servicecenter-6.0.1-SNAPSHOT.jar -n test
Copy files and directories to and from containers.
Examples:
# !!!Important Note!!!
# Requires that the 'tar' binary is present in your container
# image. If 'tar' is not present, 'kubectl cp' will fail.
#
# For advanced use cases, such as symlinks, wildcard expansion or
# file mode preservation consider using 'kubectl exec'.
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
tar cf - /tmp/foo | kubectl exec -i -n <some-namespace> <some-pod> -- tar xf - -C /tmp/bar
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
# Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
# Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
Options:
-c, --container='': Container name. If omitted, the first container in the pod will be chosen
--no-preserve=false: The copied file/directory's ownership and permissions will not be preserved in the container
Usage:
kubectl cp <file-spec-src> <file-spec-dest> [options]
更多推荐
已为社区贡献52条内容
所有评论(0)