Sometimes, we may get into situations where we need files from Kubernetes (K8S) pods to local file system & vice versa.
K8S has built-in commands for copying resources into & from K8S pods.
Case 1: To copy into local system from remote pods
kubectl cp <namespace_of_pod>/<pod_generated_name>:<source_copying_dir_path> <destination_local_dir_path>
kubectl cp catalog /catalog-app-es1xy2323sds:/appl/repositories ~/
(here, I am copying the directory /appl/repositories from remote pod named catalog-app-es1xy2323sds (generated name) from Kubernetes cluster to local root path ~/
Case 2: To copy from local system to remote pods
kubectl cp <source_local_dir_path> <namespace_of_pod>/<pod_generated_name>:<destination_copying_dir_path>
kubectl cp ~/config catalog /catalog-app-es1xy2323sds:/appl/repositories
(here, I am copying the directory ~/config from local file system to remote pod named catalog-app-es1xy2323sds (generated name) in the namespace catalog)
you can search for all the namespaces using
kubectl get namespaces
you can search all the pods for a particular namespace using
kubectl get pods -n <namespace_name>
No comments:
Post a Comment