I stumbled upon this thread while searching for similar errors I’ve encountered when attempting to copy a file from my Kubernetes pod to my local host. In my specific case, I realized that I need to specify the path to the pod’s file system, which resides under /host:
1 SSH into my pod hosted on an AKS cluster:
ssh -o 'ProxyCommand ssh -p 2022 -W %h:%p [email protected]' [email protected]
1.1. Check the user ID:
azureuser@aks-nodepool1-39416372-vmss000009:~$ whoami
azureuser
azureuser@aks-nodepool1-39416372-vmss000009:~$ id
uid=1000(azureuser) gid=1000(azureuser) groups=1000(azureuser),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),119(netdev),120(lxd)
1.2. Create a test file:
azureuser@aks-nodepool1-39416372-vmss000009:~$ echo "test" > test.txt
azureuser@aks-nodepool1-39416372-vmss000009:~$ pwd
/home/azureuser
azureuser@aks-nodepool1-39416372-vmss000009:~$ ls
test.txt
2.1. From my local host, I attempted to search for the file under the default / directory as ‘root’:
PS D:\> kubectl exec -i -t node-debugger-aks-nodepool1-39416372-vmss000009-sbncw -c debugger -- whoami
root
PS D:\> kubectl exec -i -t node-debugger-aks-nodepool1-39416372-vmss000009-sbncw -c debugger -- id
uid=0(root) gid=0(root) groups=0(root)
PS D:\> kubectl exec -i -t node-debugger-aks-nodepool1-39416372-vmss000009-sbncw -c debugger -- ls /home/azureuser
ls: /home/azureuser: No such file or directory
command terminated with exit code 1
2.2. However, the file is actually located in /host, which corresponds to the pod’s file system (I’m still wrapping my head around this):
PS D:\> kubectl exec -i -t node-debugger-aks-nodepool1-39416372-vmss000009-sbncw -c debugger -- ls /host/home/azureuser
test.txt
2.3. Now that I’ve corrected the path, the cp command should work:
PS D:\Repos> kubectl cp node-debugger-aks-nodepool1-39416372-vmss000009-sbncw:host/home/azureuser/test.txt \test.txt
PS D:\> dir \test.txt
Directory: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 21/02/2024 13:44 5 test.txt
tar: Removing leading / from member names
error) – Jefe