Advertisement
c2c2_

Kubernetes: cp help

Nov 17th, 2023 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. Copy files and directories to and from containers.
  2.  
  3. Examples:
  4. # !!!Important Note!!!
  5. # Requires that the 'tar' binary is present in your container
  6. # image. If 'tar' is not present, 'kubectl cp' will fail.
  7. #
  8. # For advanced use cases, such as symlinks, wildcard expansion or
  9. # file mode preservation, consider using 'kubectl exec'.
  10.  
  11. # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  12. tar cf - /tmp/foo | kubectl exec -i -n <some-namespace> <some-pod> -- tar xf - -C /tmp/bar
  13.  
  14. # Copy /tmp/foo from a remote pod to /tmp/bar locally
  15. kubectl exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
  16.  
  17. # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  18. kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
  19.  
  20. # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  21. kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
  22.  
  23. # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  24. kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
  25.  
  26. # Copy /tmp/foo from a remote pod to /tmp/bar locally
  27. kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
  28.  
  29. Options:
  30. -c, --container='':
  31. Container name. If omitted, use the kubectl.kubernetes.io/default-container annotation for selecting the
  32. container to be attached or the first container in the pod will be chosen
  33.  
  34. --no-preserve=false:
  35. The copied file/directory's ownership and permissions will not be preserved in the container
  36.  
  37. --retries=0:
  38. Set number of retries to complete a copy operation from a container. Specify 0 to disable or any negative
  39. value for infinite retrying. The default is 0 (no retry).
  40.  
  41. Usage:
  42. kubectl cp <file-spec-src> <file-spec-dest> [options]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement