How to Copy Files and Folder from Kubernetes Pods ?
In 5G Telcom networks, almost all network elements (RAN, CORE & IMS) are moving to cloud using the cloud native applications. These cloud native applications runs on the Kubernetes workers nodes as a pods or containers. When these application are running, they generates different types of debug, performance, alarm logs and stored in some directory within the pod.
When a developer or a tester has to debug or troubleshoot any issue causing problem in the network, they make use of logs generated by the application. Not all the issue can be debug online inside the pod, so in many cases the logs has to be copied/transferred from the pods to local machines for offline debugging.
In this post, we will dicuss how log files and folder can be transferred to Master Node using kubectl cp command. Best thing about kubectl cp that it does not require credential everytime when we transfer file/folders.
How to Copy files and folder from Pod?
A user can copy the files and folder using kubectl cp command. The whole procedure we can define in two steps.
- Using kubectl cp command transfer file or folder to Master Node
- Using SCP command transfer file or folder to the Local Machine
kubectl cp command syntax
Following the syntax for the kubectl cp command and further explained with the examples.
- kubectl cp <source_path/file> <destination_path/file>
Copy File from Pod to Master Node: While copy a file from a pod, we need the pod name, pod namespace, file location within the pod. For example lets consider pod name is n2transportmanager, and this pod is deployed with a namespace as 5gnb and the file is to be transfer is available at root with name as gnbamf_capture.pcap . Destination path can be taken as /home/techplayon/ at Master node in the example, then final command will appear as following. Once file is available on Master node, user can copy to Local Machine using SCP command.
- kubect cp -n <namespace> <pod_name:/path> <destination_path/file>
- kubect cp -n 5gnb n2transportmanager:/gnbamf_capture.pcap /home/techplayon/ gnbamf_capture.pcap
Copy File from Master Node to Pod: For example, consider a sceranio, where some developer want to apply a patch for debugging and want to transfer patch-binary to the pod. The user can first transfer the patch-binary file from Local Machine to Master Node and then can transferred to the pod using kubectl cp command. First navigate to the folder on Master Node where patch-binary is available and formulate command according to following.
- kubectl cp <source_path/file> <pod_name:/path> -n <namespace>
- kubect cp patch-binary n2transportmanager:/opt/tp/bin/patch-binary -n 5gnb
Copy Complete Folder Pod to Master Node: Similar commands will work for copy complete folder using kubectl cp. For example, lets assume user want to copy a folder having logs file at /var/log at nr2transportmanager pod. We can desing our kubectl command as following.
- kubect cp -n 5gnb n2transportmanager:/var/log /home/techplayon/log
- Linux Basic Commands
- tar.gz – Linux tar command examples
- 4G LTE Important QXDM Log Packets
- Kubernetes – Kubectl working and Common Commands
- Helm – What is it Telco Cloud ?