Skip to content

Commit 8d490c4

Browse files
committed
Update kubectl debug KEP implementation details
This corrects the KEP for details that changed in the implementation of `kubectl alpha debug`
1 parent 954acfe commit 8d490c4

File tree

1 file changed

+90
-59
lines changed

1 file changed

+90
-59
lines changed

keps/sig-cli/1441-kubectl-debug/README.md

Lines changed: 90 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
- [Debug Container Naming](#debug-container-naming)
1616
- [Container Namespace Targeting](#container-namespace-targeting)
1717
- [Interactive Troubleshooting and Automatic Attaching](#interactive-troubleshooting-and-automatic-attaching)
18-
- [Proposed Ephemeral Debug Arguments](#proposed-ephemeral-debug-arguments)
1918
- [Pod Troubleshooting by Copy](#pod-troubleshooting-by-copy)
2019
- [Creating a Debug Container by copy](#creating-a-debug-container-by-copy)
2120
- [Modify Application Image by Copy](#modify-application-image-by-copy)
@@ -28,6 +27,7 @@
2827
- [Notes/Constraints/Caveats (Optional)](#notesconstraintscaveats-optional)
2928
- [Risks and Mitigations](#risks-and-mitigations)
3029
- [Design Details](#design-details)
30+
- [Full <code>kubectl debug</code> Arguments](#full--arguments)
3131
- [Test Plan](#test-plan)
3232
- [Graduation Criteria](#graduation-criteria)
3333
- [Alpha -&gt; Beta Graduation](#alpha---beta-graduation)
@@ -158,6 +158,9 @@ separate debugging facilities for Windows containers.
158158

159159
## Proposal
160160

161+
`kubectl debug` supports a number of debugging modes, described in the
162+
following sections.
163+
161164
### Pod Troubleshooting with Ephemeral Debug Container
162165

163166
We will add a new command `kubectl debug` that will:
@@ -176,6 +179,17 @@ We will add a new command `kubectl debug` that will:
176179
We will attempt to make `kubectl debug` useful with a minimal of arguments
177180
by using reasonable defaults where possible.
178181

182+
```
183+
Examples:
184+
# Create an interactive debugging session in pod mypod and immediately attach to it.
185+
# (requires the EphemeralContainers feature to be enabled in the cluster)
186+
kubectl debug mypod -it --image=busybox
187+
188+
# Create a debug container named debugger using a custom automated debugging image.
189+
# (requires the EphemeralContainers feature to be enabled in the cluster)
190+
kubectl debug --image=myproj/debug-tools -c debugger mypod
191+
```
192+
179193
#### Debug Container Naming
180194

181195
Currently, there is no support for deleting or recreating ephemeral containers.
@@ -196,39 +210,8 @@ that support container namespace targeting.
196210
#### Interactive Troubleshooting and Automatic Attaching
197211

198212
Since the primary use case for `kubectl debug` is interactive troubleshooting,
199-
`kubectl debug` will automatically attach to the console of the newly created
200-
ephemeral container and will default to creating containers with `Stdin` and
201-
`TTY` enabled.
202-
203-
These may be disabled via command line flags.
204-
205-
#### Proposed Ephemeral Debug Arguments
206-
207-
```
208-
% kubectl help debug
209-
Execute a container in a pod.
210-
211-
Examples:
212-
# Start an interactive debugging session with a debian image
213-
kubectl debug mypod --image=debian
214-
215-
# Run a debugging session in the same namespace as target container 'myapp'
216-
# (Useful for debugging other containers when shareProcessNamespace is false)
217-
kubectl debug mypod --target=myapp
218-
219-
Options:
220-
-a, --attach=true: Automatically attach to container once created
221-
-c, --container='': Container name.
222-
-i, --stdin=true: Pass stdin to the container
223-
--image='': Required. Container image to use for debug container.
224-
--target='': Target processes in this container name.
225-
-t, --tty=true: Stdin is a TTY
226-
227-
Usage:
228-
kubectl debug (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...] [options]
229-
230-
Use "kubectl options" for a list of global command-line options (applies to all commands).
231-
```
213+
`kubectl debug` supports automatically attaching to the ephemeral container
214+
using the same conventions as `kubectl run`.
232215

233216
### Pod Troubleshooting by Copy
234217

@@ -243,16 +226,10 @@ created:
243226

244227
```
245228
Options:
246-
--copy-to='': Create a copy of the target Pod with this name.
247-
--copy-labels=false: When used with `--copy-to`, specifies whether labels
248-
should also be copied. Note that copying labels may cause
249-
the copy to receive traffic from a service or a replicaset
250-
to kill other Pods.
251-
--delete-old=false: When used with `--copy-to`, delete the original Pod.
252-
--edit=false: Open an editor to modify the generated Pod prior to creation.
253-
--same-node=false: Schedule the copy of target Pod on the same node.
254-
--share-processes=true: When used with `--copy-to`, enable process namespace
255-
sharing in the copy.
229+
--copy-to='': Create a copy of the target Pod with this name.
230+
--replace=false: When used with '--copy-to', delete the original Pod
231+
--same-node=false: When used with '--copy-to', schedule the copy of target Pod on the same node.
232+
--share-processes=true: When used with '--copy-to', enable process namespace sharing in the copy.
256233
```
257234

258235
The modification `kubectl debug` makes to `Pod.Spec.Containers` depends on the
@@ -266,8 +243,8 @@ the Pod copy.
266243

267244
```
268245
Examples:
269-
# Create a copy of 'mypod' with a new debugging container and attach to it
270-
kubectl debug mypod --copy-to=mypod-debug --image=debian --attach -- bash
246+
# Create a debug container as a copy of the original Pod and attach to it
247+
kubectl debug mypod -it --image=busybox --copy-to=my-debugger
271248
```
272249

273250
#### Modify Application Image by Copy
@@ -277,8 +254,8 @@ create a copy of the target pod with a new image for one of the containers.
277254

278255
```
279256
Examples:
280-
# Create a copy of 'mypod' with the debugging image for container 'app'
281-
kubectl debug mypod --copy-to=mypod-debug --image=myapp-image:debug --container=myapp -- myapp --debug=5
257+
# Create a copy of mypod named my-debugger with my-container's image changed to busybox
258+
kubectl debug mypod --image=busybox --container=my-container --copy-to=my-debugger -- sleep 1d
282259
```
283260

284261
Note that the Pod API allows updates of container images in-place, so
@@ -297,19 +274,13 @@ pod with the following fields set:
297274
* `hostPID: true`
298275
* `restartPolicy: Never`
299276

300-
Additionally, `/` on the node will be mounted as a HostPath volume.
277+
Additionally, the node's '/' will be mounted at `/host`.
301278

302279
```
303280
Examples:
304-
# Start an interactive debugging session on mynode with a debian image
305-
kubectl debug node/mynode --image=debian
306-
307-
Options:
308-
-a, --attach=true: Automatically attach to container once created
309-
-c, --container='': Container name.
310-
-i, --stdin=true: Pass stdin to the container
311-
--image='': Required. Container image to use for debug container.
312-
-t, --tty=true: Stdin is a TTY
281+
# Create an interactive debugging session on a node and immediately attach to it.
282+
# The container will run in the host namespaces and the host's filesystem will be mounted at /host
283+
kubectl debug node/mynode -it --image=busybox
313284
```
314285

315286
### User Stories
@@ -433,6 +404,65 @@ is to run his team's autodiagnose script:
433404

434405
## Design Details
435406

407+
### Full `kubectl debug` Arguments
408+
409+
```
410+
Debug cluster resources using interactive debugging containers.
411+
412+
'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will
413+
be used by default if resource is not specified.
414+
415+
The action taken by 'debug' varies depending on what resource is specified. Supported actions include:
416+
417+
* Workload: Create a copy of an existing pod with certain attributes changed, for example changing the image tag to a new version.
418+
* Workload: Add an ephemeral container to an already running pod, for example to add debugging utilities without restarting the pod.
419+
* Node: Create a new pod that runs in the node's host namespaces and can access the node's filesystem.
420+
421+
Alpha disclaimer: command line flags may change
422+
423+
Examples:
424+
# Create an interactive debugging session in pod mypod and immediately attach to it.
425+
# (requires the EphemeralContainers feature to be enabled in the cluster)
426+
kubectl debug mypod -it --image=busybox
427+
428+
# Create a debug container named debugger using a custom automated debugging image.
429+
# (requires the EphemeralContainers feature to be enabled in the cluster)
430+
kubectl debug --image=myproj/debug-tools -c debugger mypod
431+
432+
# Create a debug container as a copy of the original Pod and attach to it
433+
kubectl debug mypod -it --image=busybox --copy-to=my-debugger
434+
435+
# Create a copy of mypod named my-debugger with my-container's image changed to busybox
436+
kubectl debug mypod --image=busybox --container=my-container --copy-to=my-debugger -- sleep 1d
437+
438+
# Create an interactive debugging session on a node and immediately attach to it.
439+
# The container will run in the host namespaces and the host's filesystem will be mounted at /host
440+
kubectl debug node/mynode -it --image=busybox
441+
442+
Options:
443+
--arguments-only=false: If specified, everything after -- will be passed to the new container as Args instead of
444+
Command.
445+
--attach=false: If true, wait for the container to start running, and then attach as if 'kubectl attach ...' were
446+
called. Default false, unless '-i/--stdin' is set, in which case the default is true.
447+
-c, --container='': Container name to use for debug container.
448+
--copy-to='': Create a copy of the target Pod with this name.
449+
--env=[]: Environment variables to set in the container.
450+
--image='': Container image to use for debug container.
451+
--image-pull-policy='': The image pull policy for the container.
452+
--quiet=false: If true, suppress informational messages.
453+
--replace=false: When used with '--copy-to', delete the original Pod
454+
--same-node=false: When used with '--copy-to', schedule the copy of target Pod on the same node.
455+
--share-processes=true: When used with '--copy-to', enable process namespace sharing in the copy.
456+
-i, --stdin=false: Keep stdin open on the container(s) in the pod, even if nothing is attached.
457+
--target='': When debugging a pod, target processes in this container name.
458+
-t, --tty=false: Allocate a TTY for the debugging container.
459+
460+
Usage:
461+
kubectl debug (POD | KIND '/' NAME) --image=image [ -- COMMAND [args...] ]
462+
463+
Use "kubectl options" for a list of global command-line options (applies to all commands).
464+
```
465+
436466
### Test Plan
437467

438468
In addition to standard unit tests for `kubectl`, the `debug` command will be
@@ -446,7 +476,7 @@ test prior to Alpha -> Beta graduation.
446476
#### Alpha -> Beta Graduation
447477

448478
- [ ] Ephemeral Containers API has graduated to Beta
449-
- [ ] A task on https://kubernetes.io/docs/tasks/ describes how to troubleshoot
479+
- [x] A task on https://kubernetes.io/docs/tasks/ describes how to troubleshoot
450480
a running pod using Ephemeral Containers.
451481
- [ ] A survey sent to early adopters doesn't reveal any major shortcomings.
452482
- [ ] Test plan is amended to address the most common user journeys.
@@ -703,6 +733,7 @@ _This section must be completed when targeting beta graduation to a release._
703733
- *2019-12-05*: Updated KEP for expanded debug targets.
704734
- *2020-01-09*: Updated KEP for debugging nodes and mark implementable.
705735
- *2020-01-15*: Added test plan.
736+
- *2020-09-20*: Updated to reflect actual implementation details.
706737

707738
## Drawbacks
708739

0 commit comments

Comments
 (0)