cop file from remote conatiner to localmachine?

12/28/2020

how i acces my namespace: kubens namespace how i access my pod: acces my container: kubectl exec -it hello-6b588fc8c-jz89q --container test -- bash

i wante to cp a file from the filebeat container. but not work i try

-- Ahmed Hilali
kubernetes

1 Answer

12/28/2020

From the kubectl cp --help output, an example is provided for your use case (copying from a remote pod to your local filesystem):

# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

In your case, I believe the command would be

kubectl cp <namespace-of-pod>/dsp-onboarding-6b588fc8c-jz89q:/app/data/logs/dsp-onboarding.json.log . -c filebeat

Note the -c option is necessary in your case, since you want to cp the file off of a specific container in the pod.

-- Shane Bishop
Source: StackOverflow