Adding kubectl cp command examples in cheatsheet
This commit is contained in:
parent
0a0b8859e3
commit
d0f94114a1
|
|
@ -323,6 +323,24 @@ kubectl exec my-pod -c my-container -- ls / # Run command in existing po
|
|||
kubectl top pod POD_NAME --containers # Show metrics for a given pod and its containers
|
||||
kubectl top pod POD_NAME --sort-by=cpu # Show metrics for a given pod and sort it by 'cpu' or 'memory'
|
||||
```
|
||||
## Copy files and directories to and from containers
|
||||
|
||||
```bash
|
||||
kubectl cp /tmp/foo_dir my-pod:/tmp/bar_dir # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the current namespace
|
||||
kubectl cp /tmp/foo my-pod:/tmp/bar -c my-container # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
|
||||
kubectl cp /tmp/foo my-namespace/my-pod:/tmp/bar # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace my-namespace
|
||||
kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar # Copy /tmp/foo from a remote pod to /tmp/bar locally
|
||||
```
|
||||
{{< note >}}
|
||||
`kubectl cp` 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`.
|
||||
{{< /note >}}
|
||||
|
||||
```bash
|
||||
tar cf - /tmp/foo | kubectl exec -i -n my-namespace my-pod -- tar xf - -C /tmp/bar # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace my-namespace
|
||||
kubectl exec -n my-namespace my-pod -- tar cf - /tmp/foo | tar xf - -C /tmp/bar # Copy /tmp/foo from a remote pod to /tmp/bar locally
|
||||
```
|
||||
|
||||
|
||||
## Interacting with Deployments and Services
|
||||
```bash
|
||||
|
|
|
|||
Loading…
Reference in New Issue