Editing Kubectl cp

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
{{lc}}
 
{{lc}}
kubectl cp Copy files and directories to and from containers and between containers. https://spacelift.io/blog/kubectl-cp
 
 
* https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#cp
 
* https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#cp
 
  [[kubectl]] cp
 
  [[kubectl]] cp
[[kubectl cp --help]]
 
  
  kubectl cp YourRemoteContainer:/yourdestinationdatafolder/ /your/local/folder/
+
  kubectl cp youfile.txt YourRemotePod:/yourdestinationdata
kubectl cp YourNamespace/YourRemoteContainer:/yourdestinationdata/ /your/local/folder/
 
  
  kubectl cp youfile.txt YourRemoteContainer:/yourdestinationdata
+
  kubectl cp YourRemotePod:/yourdestinationdata /your/local/folder
  kubectl cp /your/local/folder/* [[YourRemoteContainer]]:/yourdestinationdata
+
  kubectl cp YourNamespace/YourRemotePod:/yourdestinationdata /your/local/folder
  
 +
<pre>
 +
kubectl cp --help
 +
Copy files and directories to and from containers.
 +
 +
Examples:
 +
  # !!!Important Note!!!
 +
  # Requires that the 'tar' binary is present in your container
 +
  # image.  If 'tar' is not present, 'kubectl cp' will fail.
 +
  #
 +
  # For advanced use cases, such as symlinks, wildcard expansion or
 +
  # file mode preservation, consider using 'kubectl exec'.
 +
 +
  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
 +
  tar cf - /tmp/foo | kubectl exec -i -n <some-namespace> <some-pod> -- tar xf - -C /tmp/bar
 +
 +
  # Copy /tmp/foo from a remote pod to /tmp/bar locally
 +
  kubectl exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
 +
 +
  # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
 +
  kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
 +
 +
  # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
 +
  kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
 +
 +
  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
 +
  kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
 +
 +
  # Copy /tmp/foo from a remote pod to /tmp/bar locally
 +
  kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
 +
 +
Options:
 +
    -c, --container='':
 +
        Container name. If omitted, use the kubectl.kubernetes.io/default-container annotation for
 +
        selecting the container to be attached or the first container in the pod will be chosen
 +
 +
    --no-preserve=false:
 +
        The copied file/directory's ownership and permissions will not be preserved in the
 +
        container
 +
 +
    --retries=0:
 +
        Set number of retries to complete a copy operation from a container. Specify 0 to disable
 +
        or any negative value for infinite retrying. The default is 0 (no retry).
 +
 +
Usage:
 +
  kubectl cp <file-spec-src> <file-spec-dest> [options]
 +
 +
Use "kubectl options" for a list of global command-line options (applies to all commands).
 +
</pre>
  
  
Line 29: Line 74:
 
  [[kubectl exec myalpine -- df -kh]]
 
  [[kubectl exec myalpine -- df -kh]]
 
  [[mount]] | [[grep ^/dev/]] | grep -v /etc | awk '{print $3}'
 
  [[mount]] | [[grep ^/dev/]] | grep -v /etc | awk '{print $3}'
 
 
== Errors ==
 
 
[[error: source and destination are required]]
 
Solution: remove trailing /* from your local directory name
 
 
[[error: unable to upgrade connection]]: [[container not found]]("your-container")
 
 
  
 
== Related ==
 
== Related ==
Line 43: Line 79:
 
* <code>[[docker cp]]</code>
 
* <code>[[docker cp]]</code>
 
* [[Kube-dump]]
 
* [[Kube-dump]]
* <code>[[kubectl.kubernetes.io/default-container]]</code>
 
* [[kubectl exec]]
 
  
 
== See also ==
 
== See also ==

Please note that all contributions to wikieduonline may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wikieduonline:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Advertising: