如何将文件从 kubernetes Pods 复制到本地系统 [英] How to copy files from kubernetes Pods to local system
问题描述
我正在尝试将文件从 Kubernetes Pod 复制到我的本地系统.运行以下命令时出现以下错误:
I'm trying to copy files from Kubernetes Pods to my local system. I am getting the below error while running following command:
kubectl cp aks-ssh2-6cd4948f6f-fp9tl:/home/azureuser/test.cap ./test.cap
输出:
tar:home/azureuser/test:无法统计:没有那个文件或目录 tar:由于先前的错误错误而以失败状态退出:home/azureuser/test 没有那个文件或目录
tar: home/azureuser/test: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors error: home/azureuser/test no such file or directory
我可以看到上面给定路径下的文件.我真的很困惑.
I could see the file under above given path. I am really confused.
能帮帮我吗?
推荐答案
如kubectl
帮助中所述:
kubectl cp --help
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.
# 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
Usage:
kubectl cp <file-spec-src> <file-spec-dest> [options]
Use "kubectl options" for a list of global command-line options (applies to all commands).
您也可以登录您的容器
并检查文件是否存在:
You can also login to your Containter
and check if file is there:
kubectl exec -it aks-ssh2-6cd4948f6f-fp9tl /bin/bash
ls -la /home/azureuser/test.cap
如果这仍然不起作用,请尝试:
If this still doesn't work, try:
您可以尝试将文件复制到 workdir,然后仅使用文件名重试复制它们.这很奇怪,但现在有效.
You may try to copy your files to workdir and then retry to copy them using just their names. It's weird, but it works for now.
在此处kchugalinskiy的建议问题/58692" rel="noreferrer">#58692.
Consider advice of kchugalinskiy here #58692.
这篇关于如何将文件从 kubernetes Pods 复制到本地系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!