# kubectl debug

kubectl debugSynopsisDebug 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.Note: When a non-root user is configured for the entire target Pod, some capabilities granted by debug profile may not work.kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ] Examples # Create an interactive debugging session in pod mypod and immediately attach to it. kubectl debug mypod -it --image=busybox # Create an interactive debugging session for the pod in the file pod.yaml and immediately attach to it. # (requires the EphemeralContainers feature to be enabled in the cluster) kubectl debug -f pod.yaml -it --image=busybox # Create a debug container named debugger using a custom automated debugging image. kubectl debug --image=myproj/debug-tools -c debugger mypod # Create a copy of mypod adding a debug container and attach to it kubectl debug mypod -it --image=busybox --copy-to=my-debugger # Create a copy of mypod changing the command of mycontainer kubectl debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh # Create a copy of mypod changing all container images to busybox kubectl debug mypod --copy-to=my-debugger --set-image=*=busybox # Create a copy of mypod adding a debug container and changing container images 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 kubectl debug node/mynode -it --image=busybox Options--arguments-onlyIf specified, everything after -- will be passed to the new container as Args instead of Command.--attachIf 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.-c, --container stringContainer name to use for debug container.--copy-to stringCreate a copy of the target Pod with this name.--custom stringPath to a JSON or YAML file containing a partial container spec to customize built-in debug profiles.--env stringToString Default: []Environment variables to set in the container.-f, --filename stringsidentifying the resource to debug-h, --helphelp for debug--image stringContainer image to use for debug container.--image-pull-policy stringThe image pull policy for the container. If left empty, this value will not be specified by the client and defaulted by the server.--keep-annotationsIf true, keep the original pod annotations.(This flag only works when used with '--copy-to')--keep-init-containers Default: trueRun the init containers for the pod. Defaults to true.(This flag only works when used with '--copy-to')--keep-labelsIf true, keep the original pod labels.(This flag only works when used with '--copy-to')--keep-livenessIf true, keep the original pod liveness probes.(This flag only works when used with '--copy-to')--keep-readinessIf true, keep the original pod readiness probes.(This flag only works when used with '--copy-to')--keep-startupIf true, keep the original startup probes.(This flag only works when used with '--copy-to')--profile string Default: "legacy"Options are "legacy", "general", "baseline", "netadmin", "restricted" or "sysadmin".-q, --quietIf true, suppress informational messages.--replaceWhen used with '--copy-to', delete the original Pod.--same-nodeWhen used with '--copy-to', schedule the copy of target Pod on the same node.--set-image stringToString Default: []When used with '--copy-to', a list of name=image pairs for changing container images, similar to how 'kubectl set image' works.--share-processes Default: trueWhen used with '--copy-to', enable process namespace sharing in the copy.-i, --stdinKeep stdin open on the container(s) in the pod, even if nothing is attached.--target stringWhen using an ephemeral container, target processes in this container name.-t, --ttyAllocate a TTY for the debugging container.Parent Options Inherited--as stringUsername to impersonate for the operation. User could be a regular user or a service account in a namespace.--as-group stringsGroup to impersonate for the operation, this flag can be repeated to specify multiple groups.--as-uid stringUID to impersonate for the operation.--cache-dir string Default: "$HOME/.kube/cache"Default cache directory--certificate-authority stringPath to a cert file for the certificate authority--client-certificate stringPath to a client certificate file for TLS--client-key stringPath to a client key file for TLS--cluster stringThe name of the kubeconfig cluster to use--context stringThe name of the kubeconfig context to use--disable-compressionIf true, opt-out of response compression for all requests to the server--insecure-skip-tls-verifyIf true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure--kubeconfig stringPath to the kubeconfig file to use for CLI requests.--kuberc stringPath to the kuberc file to use for preferences. This can be disabled by exporting KUBECTL_KUBERC=false feature gate or turning off the feature KUBERC=off.--match-server-versionRequire server version to match client version-n, --namespace stringIf present, the namespace scope for this CLI request--password stringPassword for basic authentication to the API server--profile-output string Default: "profile.pprof"Name of the file to write the profile to--request-timeout string Default: "0"The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.-s, --server stringThe address and port of the Kubernetes API server--storage-driver-buffer-duration duration Default: 1m0sWrites in the storage driver will be buffered for this duration, and committed to the non memory backends as a single transaction--storage-driver-db string Default: "cadvisor"database name--storage-driver-host string Default: "localhost:8086"database host:port--storage-driver-password string Default: "root"database password--storage-driver-secureuse secure connection with database--storage-driver-table string Default: "stats"table name--storage-driver-user string Default: "root"database username--tls-server-name stringServer name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used--token stringBearer token for authentication to the API server--user stringThe name of the kubeconfig user to use--username stringUsername for basic authentication to the API server--version version[=true]--version, --version=raw prints version information and quits; --version=vX.Y.Z... sets the reported version--warnings-as-errorsTreat warnings received from the server as errors and exit with a non-zero exit codeSee Alsokubectl - kubectl controls the Kubernetes cluster managerThis page is automatically generated.If you plan to report an issue with this page, mention that the page is auto-generated in your issue description. The fix may need to happen elsewhere in the Kubernetes project.