Learn how to copy Files and Directories to and from a Kubernetes Container POD using “kubectl cp” command with example and details.
Copying Files to a Kubernetes Container:
To copy a file or directory to a Kubernetes container, you can use the kubectl cp
command followed by the local file path and the destination on the pod. Here is the general
syntax:
kubectl cp <file-to-copy> <namespace>/<pod-name>:<path-in-container>
For instance, if you wanted to copy a local file named example.txt
to the /app/
directory in a pod named mypod
in the default
namespace, the command would look like this:
kubectl cp example.txt default/mypod:/app/
If you’re copying a directory, just add -r
for recursive:
kubectl cp -r <directory-to-copy> <namespace>/<pod-name>:<path-in-container>
Copying Files from a Kubernetes Container:
Retrieving files or directories from a Kubernetes container is just as straightforward. The syntax is similar, but the source and destination are swapped:
kubectl cp <namespace>/<pod-name>:<path-in-container> <local-destination-path>
For example, to copy a file named example.txt
from the /app/
directory in the mypod
pod to your local machine, you’d run:
kubectl cp default/mypod:/app/example.txt .
The .
signifies the current directory on your local machine.
Understanding how to copy Files and Directories to and from a Kubernetes Container POD is a valuable skill in managing and troubleshooting your applications.
To learn more about golang, Please refer given below link.
https://www.techieindoor.com/kubernetes-tutorial/
References:
https://en.wikipedia.org/wiki/Kubernetes