如何将文件从kubernetes Pod复制到本地系统 [英] How to copy files from kubernetes Pods to local system

查看:2920
本文介绍了如何将文件从kubernetes Pod复制到本地系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从Kubernetes Pods复制到本地系统.运行以下命令时出现以下错误:

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/测试没有这样的文件或目录

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

您还可以登录到Containter并检查文件是否存在:

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 的建议issues/58692"rel =" noreferrer>#58692 .

Consider advice of kchugalinskiy here #58692.

这篇关于如何将文件从kubernetes Pod复制到本地系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆