rkubectl_app/cli/command/troubleshoot/debug.rs
1use super::*;
2
3// Debug cluster resources using interactive debugging containers.
4
5// 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will
6// be used by default if no resource is specified.
7
8// The action taken by 'debug' varies depending on what resource is specified. Supported actions include:
9
10// * Workload: Create a copy of an existing pod with certain attributes changed, for example changing the image tag to a
11// new version.
12// * Workload: Add an ephemeral container to an already running pod, for example to add debugging utilities without
13// restarting the pod.
14// * Node: Create a new pod that runs in the node's host namespaces and can access the node's filesystem.
15
16// Note: When a non-root user is configured for the entire target Pod, some capabilities granted by debug profile may not
17// work.
18
19// Examples:
20// # Create an interactive debugging session in pod mypod and immediately attach to it.
21// kubectl debug mypod -it --image=busybox
22
23// # Create an interactive debugging session for the pod in the file pod.yaml and immediately attach to it.
24// # (requires the EphemeralContainers feature to be enabled in the cluster)
25// kubectl debug -f pod.yaml -it --image=busybox
26
27// # Create a debug container named debugger using a custom automated debugging image.
28// kubectl debug --image=myproj/debug-tools -c debugger mypod
29
30// # Create a copy of mypod adding a debug container and attach to it
31// kubectl debug mypod -it --image=busybox --copy-to=my-debugger
32
33// # Create a copy of mypod changing the command of mycontainer
34// kubectl debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh
35
36// # Create a copy of mypod changing all container images to busybox
37// kubectl debug mypod --copy-to=my-debugger --set-image=*=busybox
38
39// # Create a copy of mypod adding a debug container and changing container images
40// kubectl debug mypod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,sidecar=sidecar:debug
41
42// # Create an interactive debugging session on a node and immediately attach to it.
43// # The container will run in the host namespaces and the host's filesystem will be mounted at /host
44// kubectl debug node/mynode -it --image=busybox
45
46// Options:
47// --arguments-only=false:
48// If specified, everything after -- will be passed to the new container as Args instead of Command.
49
50// --attach=false:
51// If true, wait for the container to start running, and then attach as if 'kubectl attach ...' were called.
52// Default false, unless '-i/--stdin' is set, in which case the default is true.
53
54// -c, --container='':
55// Container name to use for debug container.
56
57// --copy-to='':
58// Create a copy of the target Pod with this name.
59
60// --custom='':
61// Path to a JSON or YAML file containing a partial container spec to customize built-in debug profiles.
62
63// --env=[]:
64// Environment variables to set in the container.
65
66// -f, --filename=[]:
67// identifying the resource to debug
68
69// --image='':
70// Container image to use for debug container.
71
72// --image-pull-policy='':
73// The image pull policy for the container. If left empty, this value will not be specified by the client and
74// defaulted by the server.
75
76// --keep-annotations=false:
77// If true, keep the original pod annotations.(This flag only works when used with '--copy-to')
78
79// --keep-init-containers=true:
80// Run the init containers for the pod. Defaults to true.(This flag only works when used with '--copy-to')
81
82// --keep-labels=false:
83// If true, keep the original pod labels.(This flag only works when used with '--copy-to')
84
85// --keep-liveness=false:
86// If true, keep the original pod liveness probes.(This flag only works when used with '--copy-to')
87
88// --keep-readiness=false:
89// If true, keep the original pod readiness probes.(This flag only works when used with '--copy-to')
90
91// --keep-startup=false:
92// If true, keep the original startup probes.(This flag only works when used with '--copy-to')
93
94// --profile='legacy':
95// Options are "legacy", "general", "baseline", "netadmin", "restricted" or "sysadmin".
96
97// -q, --quiet=false:
98// If true, suppress informational messages.
99
100// --replace=false:
101// When used with '--copy-to', delete the original Pod.
102
103// --same-node=false:
104// When used with '--copy-to', schedule the copy of target Pod on the same node.
105
106// --set-image=[]:
107// When used with '--copy-to', a list of name=image pairs for changing container images, similar to how 'kubectl
108// set image' works.
109
110// --share-processes=true:
111// When used with '--copy-to', enable process namespace sharing in the copy.
112
113// -i, --stdin=false:
114// Keep stdin open on the container(s) in the pod, even if nothing is attached.
115
116// --target='':
117// When using an ephemeral container, target processes in this container name.
118
119// -t, --tty=false:
120// Allocate a TTY for the debugging container.
121
122// Usage:
123// kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ] [options]
124
125// Use "kubectl options" for a list of global command-line options (applies to all commands).
126
127/// Debug cluster resources using interactive debugging containers.
128
129#[derive(Clone, Debug, Args)]
130pub struct Debug {
131 /// Copy the same volumes as the target pod in the debug container
132 #[arg(long)]
133 copy_volumes: bool,
134}