Skip to content

Kubernetes: Exec, port-forward, copy

4 Kubernetes commands: Exec, port-forward, copy. Click a command to see what each part does.

Index
4 items
Click a command to see what each part does.

Exec, port-forward, copy4

  • kubectl exec -it <pod> -n <namespace> -- shShell into a pod

    What each part does

    1. exec <pod>run a command in a container of the pod
    2. -itinteractive stdin + terminal
    3. --everything after this is the command, not kubectl flags
    4. shthe shell (bash if available)
  • kubectl port-forward svc/<service> <local-port>:<service-port> -n <namespace>Reach a service from your laptop

    What each part does

    1. port-forwardtunnel a local port into the cluster
    2. svc/<service>target a service (or pod/<pod>, deploy/<name>)
    3. <local-port>:<service-port>listen on localhost:<local-port>, forward to <service-port>
  • kubectl cp <namespace>/<pod>:<path> ./<file>Copy files out of / into a pod

    What each part does

    1. cpcopy files (needs tar inside the container)
    2. <namespace>/<pod>:<path>source in the pod; swap the arguments to copy into the pod
  • kubectl debug <pod> -it --image=busybox:1.36 --target=<container>Attach a debug container to a pod

    What each part does

    1. debug <pod>add an ephemeral debug container
    2. -itinteractive terminal
    3. --image=busybox:1.36image with the tools you need
    4. --target=<container>share that container's process namespace

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…