gpt4 book ai didi

kubernetes - 如何将文件从 kubernetes Pod 复制到本地系统

转载 作者:行者123 更新时间:2023-12-02 02:46:49 28 4
gpt4 key购买 nike

我正在尝试将文件从 Kubernetes Pod 复制到我的本地系统。我在运行以下命令时收到以下错误:

kubectl cp aks-ssh2-6cd4948f6f-fp9tl:/home/azureuser/test.cap ./test.cap

输出:

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

我可以在上面给定的路径下看到该文件。我真的很困惑。

你能帮我一下吗?

最佳答案

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

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

kubectl exec -it aks-ssh2-6cd4948f6f-fp9tl /bin/bash
ls -la /home/azureuser/test.cap

如果这仍然不起作用,请尝试:

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 .

关于kubernetes - 如何将文件从 kubernetes Pod 复制到本地系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407277/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com