KUBERNETES(1)(kubernetes)

πŸ’– kubectl debug β€” the bestie guide πŸ’–

okay so like. you know when a pod is being ✨unwell✨ and you're just staring at it like πŸ‘οΈπŸ‘„πŸ‘οΈ? this is the page for that. it's kubectl debug, from the kubernetes manual, and it's literally the "let me just go in there and look" command. no cap.

Eric Paris, Jan 2015 β€” that's the whole vibe, bestie. let's get into it.


🌸 NAME 🌸

kubectl debug β€” create debugging sessions for troubleshooting workloads and nodes. that's it. that's the whole job. it makes you a lil debug session so you can go poke at stuff. 🫢


✨ SYNOPSIS ✨

kubectl debug [OPTIONS]

short. sweet. iconic. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

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. (so if you're lazy and don't say what you want β€” and honestly? valid β€” it's gonna assume pods. main character behavior.)

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, adding debugging utilities without restarting the pod. (this one is so good. no restart. chef's kiss.)
  • Node: create a new pod that runs in the node's host namespaces and can access the node's filesystem. 🌐
⚠️ note bestie: when a non-root user is configured for the entire target Pod, some capabilities granted by the debug profile may not work. it's giving "permission said no". 😭

πŸŽ€ OPTIONS πŸŽ€

  • --arguments-only=false β€” if specified, everything after -- will be passed to the new container as Args instead of Command. (iykyk β€” it flips which one eats the args.)
  • --attach=false β€” if true, wait for the container to start running, and then attach, as if kubectl attach ... were called. default is false β€” unless -i/--stdin is set, in which case the default is true. sneaky lil default flip, love that for us.
  • -c, --container="" β€” container name to use for the debug container.
  • --copy-to="" β€” create a copy of the target Pod with this name.
  • --custom="" β€” path to a JSON or YAML file containing a partial container spec, to customize built-in debug profiles. bring your own vibe file ✨
  • --env=[] β€” environment variables to set in the container.
  • -f, --filename=[] β€” identifying the resource to debug.
  • --image="" β€” container image to use for the debug container.
  • --image-pull-policy="" β€” the image pull policy for the container. if left empty, this value will not be specified by the client and defaulted by the server. (so: empty = the server decides, not us. we stay out of it πŸ’…)
  • --keep-annotations=false β€” if true, keep the original pod annotations. (this flag only works when used with --copy-to)
  • --keep-init-containers=true β€” run the init containers for the pod. defaults to true. (this flag only works when used with --copy-to)
  • --keep-labels=false β€” if true, keep the original pod labels. (this flag only works when used with --copy-to)
  • --keep-liveness=false β€” if true, keep the original pod liveness probes. (this flag only works when used with --copy-to)
  • --keep-readiness=false β€” if true, keep the original pod readiness probes. (this flag only works when used with --copy-to)
  • --keep-startup=false β€” if true, keep the original startup probes. (this flag only works when used with --copy-to)
  • --profile="general" β€” options are "general", "baseline", "restricted", "netadmin" or "sysadmin". defaults to "general".
  • -q, --quiet=false β€” if true, suppress informational messages. (shhh. no thoughts, no chatter. πŸ“)
  • --replace=false β€” when used with --copy-to, delete the original Pod. (yes bestie, delete. dramatic but sometimes necessary πŸ’€)
  • --same-node=false β€” when used with --copy-to, schedule the copy of the 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-processes=true β€” when used with --copy-to, enable process namespace sharing in the copy.
  • -i, --stdin=false β€” keep stdin open on the container(s) in the pod, even if nothing is attached.
  • --target="" β€” when using an ephemeral container, target processes in this container name.
  • -t, --tty=false β€” allocate a TTY for the debugging container.

🌈 OPTIONS INHERITED FROM PARENT COMMANDS 🌈

these are the ones that come down from the parent command β€” they're not debug's own, they're the family inheritance. πŸ’œ

  • --as="" β€” username to impersonate for the operation. User could be a regular user or a service account in a namespace.
  • --as-group=[] β€” group to impersonate for the operation. This flag can be repeated to specify multiple groups.
  • --as-uid="" β€” UID to impersonate for the operation.
  • --as-user-extra=[] β€” user extras to impersonate for the operation. This flag can be repeated to specify multiple values for the same key.
  • --cache-dir="/home/username/.kube/cache" β€” default cache directory.
  • --certificate-authority="" β€” path to a cert file for the certificate authority.
  • --client-certificate="" β€” path to a client certificate file for TLS.
  • --client-key="" β€” path to a client key file for TLS.
  • --cluster="" β€” the name of the kubeconfig cluster to use.
  • --context="" β€” the name of the kubeconfig context to use.
  • --disable-compression=false β€” if true, opt-out of response compression for all requests to the server.
  • --insecure-skip-tls-verify=false β€” if true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. ⚠️ bestie, insecure means INSECURE. be so serious about this one.
  • --kubeconfig="" β€” path to the kubeconfig file to use for CLI requests.
  • --kuberc="" β€” path 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-version=false β€” require server version to match client version.
  • -n, --namespace="" β€” if present, the namespace scope for this CLI request.
  • --password="" β€” password for basic authentication to the API server.
  • --profile-output="profile.pprof" β€” name of the file to write the profile to. (yes, it's also called profile. no, not that --profile. different profile. we contain multitudes πŸ’…)
  • --proxy-url="" β€” proxy URL to use for requests to the API server.
  • --request-timeout="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. (zero = we wait forever. forever girlie behavior πŸ•°οΈ)
  • -s, --server="" β€” the address and port of the Kubernetes API server.
  • --tls-server-name="" β€” server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used.
  • --token="" β€” bearer token for authentication to the API server.
  • --user="" β€” the name of the kubeconfig user to use.
  • --username="" β€” username for basic authentication to the API server.
  • --version=false β€” --version, --version=raw prints version information and quits; --version=vX.Y.Z... sets the reported version.
  • --warnings-as-errors=false β€” treat warnings received from the server as errors and exit with a non-zero exit code.

πŸ”₯ EXAMPLE πŸ”₯

okay these are the actual ones, verbatim, no edits. go off:

# 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

that --set-image=*=busybox with the literal star? yeah that's "change ALL of them", it ate. 🌟


πŸ‘‘ SEE ALSO πŸ‘‘


πŸ“œ HISTORY πŸ“œ

January 2015, originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material β€” but hopefully they have been automatically generated since! (the way that last part is so real 😭)


and that's the whole page, bestie. πŸŽ€ this was the kubernetes manual, User section, and the version stamp at the bottom says Manuals Β· User Β· KUBERNETES(1)(kubernetes) β€” so yeah, that's the one. now go debug something, you got this. slay. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from