debug

Create an interactive debugging session in pod mypod and immediately attach to it. # (requires the EphemeralContainers feature to be enabled in the cluster)

  1. kubectl debug mypod -it --image=busybox

Create a debug container named debugger using a custom automated debugging image. # (requires the EphemeralContainers feature to be enabled in the cluster)

  1. kubectl debug --image=myproj/debug-tools -c debugger mypod

Create a copy of mypod adding a debug container and attach to it

  1. kubectl debug mypod -it --image=busybox --copy-to=my-debugger

Create a copy of mypod changing the command of mycontainer

  1. kubectl debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh

Create a copy of mypod changing all container images to busybox

  1. kubectl debug mypod --copy-to=my-debugger --set-image=*=busybox

Create a copy of mypod adding a debug container and changing container images

  1. kubectl debug mypod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,sidecar=sidecar:debug

Create an interactive debugging session on a node and immediately attach to it. # The container will run in the host namespaces and the host’s filesystem will be mounted at /host

  1. kubectl debug node/mynode -it --image=busybox

Debug cluster resources using interactive debugging containers.

‘debug’ provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource is specified.

The action taken by ‘debug’ varies depending on what resource is specified. Supported actions include:

  • Workload: Create a copy of an existing pod with certain attributes changed, for example changing the image tag to a new version.
  • Workload: Add an ephemeral container to an already running pod, for example to add debugging utilities without restarting the pod.
  • Node: Create a new pod that runs in the node’s host namespaces and can access the node’s filesystem.

Usage

$ kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ]

Flags

NameShorthandDefaultUsage
arguments-onlyfalseIf specified, everything after — will be passed to the new container as Args instead of Command.
attachfalseIf true, wait for the container to start running, and then attach as if ‘kubectl attach …’ were called. Default false, unless ‘-i/—stdin’ is set, in which case the default is true.
containercContainer name to use for debug container.
copy-toCreate a copy of the target Pod with this name.
env[]Environment variables to set in the container.
imageContainer image to use for debug container.
image-pull-policyThe image pull policy for the container. If left empty, this value will not be specified by the client and defaulted by the server.
quietqfalseIf true, suppress informational messages.
replacefalseWhen used with ‘—copy-to’, delete the original Pod.
same-nodefalseWhen used with ‘—copy-to’, schedule the copy of target Pod on the same node.
set-image[]When used with ‘—copy-to’, a list of name=image pairs for changing container images, similar to how ‘kubectl set image’ works.
share-processestrueWhen used with ‘—copy-to’, enable process namespace sharing in the copy.
stdinifalseKeep stdin open on the container(s) in the pod, even if nothing is attached.
targetWhen using an ephemeral container, target processes in this container name.
ttytfalseAllocate a TTY for the debugging container.