How to copy files from kubernetes Pods to local system

后端 未结 10 1606
暖寄归人
暖寄归人 2020-12-24 10:22

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-6cd4948         


        
10条回答
  •  梦毁少年i
    2020-12-24 11:18

    As stated inkubectl help:

    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 :/tmp/bar_dir
    
    # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
    kubectl cp /tmp/foo :/tmp/bar -c 
    
    # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace 
    kubectl cp /tmp/foo /:/tmp/bar
    
    # Copy /tmp/foo from a remote pod to /tmp/bar locally
    kubectl cp /:/tmp/foo /tmp/bar
    
    Options:
    -c, --container='': Container name. If omitted, the first container in the pod will be chosen
    
    Usage:
    kubectl cp   [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:

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

    Consider advice of kchugalinskiy here #58692.

提交回复
热议问题