Difference between revisions of "Kubectl cp"
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
kubectl cp youfile.txt remotepod:/yourdestinationdata | kubectl cp youfile.txt remotepod:/yourdestinationdata | ||
+ | <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> | ||
+ | |||
+ | |||
+ | |||
[[kubectl apply -f]] | [[kubectl apply -f]] |
Revision as of 23:15, 23 October 2023
kubectl cp
kubectl cp youfile.txt remotepod:/yourdestinationdata
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).
kubectl apply -f
https://stackoverflow.com/questions/50375826/kubernetes-how-to-download-a-persistentvolumes-content
apiVersion: v1 kind: Pod metadata: name: myalpinewithvolume spec: containers: - name: alpine image: alpine:latest command: ['ash'] tty: true stdin: true volumeMounts: - name: myvolume mountPath: /myvolume volumes: - name: myvolume persistentVolumeClaim: claimName: myPVCtoMount
kubectl cp myalpinedataaccess:/data data/ tar: removing leading '/' from member names
kubectl exec <pod_name> -- ls -la /
kubectl exec myalpine -- df -kh mount | grep ^/dev/ | grep -v /etc | awk '{print $3}'
See also
cp
,dd
,sftp
,scp
,rsync
,casync
,mv
,fio
,ln
,docker cp, kubectl cp
,minikube cp
,multipass transfer
,Copy-Item
,Xcopy
kubectl
: [cp | config | create
|delete
|edit | explain |
apply
|exec
|get
|set
|drain | uncordon | rolling-update
|rollout
|logs
|run
|auth
|label | annotate
|version
|top
|diff
|debug
|replace
|describe
|port-forward | proxy
|scale
|rollout
|api-resources
| expose deployment | expose | patch | attach | get endpoints | ~/.kube/config | kubectl logs --help | kubectl --help, kubectl-convert, kubectl autoscale, kubectl.kubernetes.io
Advertising: