15
15
- [ Debug Container Naming] ( #debug-container-naming )
16
16
- [ Container Namespace Targeting] ( #container-namespace-targeting )
17
17
- [ Interactive Troubleshooting and Automatic Attaching] ( #interactive-troubleshooting-and-automatic-attaching )
18
- - [ Proposed Ephemeral Debug Arguments] ( #proposed-ephemeral-debug-arguments )
19
18
- [ Pod Troubleshooting by Copy] ( #pod-troubleshooting-by-copy )
20
19
- [ Creating a Debug Container by copy] ( #creating-a-debug-container-by-copy )
21
20
- [ Modify Application Image by Copy] ( #modify-application-image-by-copy )
28
27
- [ Notes/Constraints/Caveats (Optional)] ( #notesconstraintscaveats-optional )
29
28
- [ Risks and Mitigations] ( #risks-and-mitigations )
30
29
- [ Design Details] ( #design-details )
30
+ - [ Full <code >kubectl debug</code > Arguments] ( #full--arguments )
31
31
- [ Test Plan] ( #test-plan )
32
32
- [ Graduation Criteria] ( #graduation-criteria )
33
33
- [ Alpha -> ; Beta Graduation] ( #alpha---beta-graduation )
@@ -158,6 +158,9 @@ separate debugging facilities for Windows containers.
158
158
159
159
## Proposal
160
160
161
+ ` kubectl debug ` supports a number of debugging modes, described in the
162
+ following sections.
163
+
161
164
### Pod Troubleshooting with Ephemeral Debug Container
162
165
163
166
We will add a new command ` kubectl debug ` that will:
@@ -176,6 +179,17 @@ We will add a new command `kubectl debug` that will:
176
179
We will attempt to make ` kubectl debug ` useful with a minimal of arguments
177
180
by using reasonable defaults where possible.
178
181
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
+
179
193
#### Debug Container Naming
180
194
181
195
Currently, there is no support for deleting or recreating ephemeral containers.
@@ -196,39 +210,8 @@ that support container namespace targeting.
196
210
#### Interactive Troubleshooting and Automatic Attaching
197
211
198
212
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 ` .
232
215
233
216
### Pod Troubleshooting by Copy
234
217
@@ -243,16 +226,10 @@ created:
243
226
244
227
```
245
228
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.
256
233
```
257
234
258
235
The modification ` kubectl debug ` makes to ` Pod.Spec.Containers ` depends on the
@@ -266,8 +243,8 @@ the Pod copy.
266
243
267
244
```
268
245
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
271
248
```
272
249
273
250
#### 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.
277
254
278
255
```
279
256
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
282
259
```
283
260
284
261
Note that the Pod API allows updates of container images in-place, so
@@ -297,19 +274,13 @@ pod with the following fields set:
297
274
* ` hostPID: true `
298
275
* ` restartPolicy: Never `
299
276
300
- Additionally, ` / ` on the node will be mounted as a HostPath volume .
277
+ Additionally, the node's '/' will be mounted at ` /host ` .
301
278
302
279
```
303
280
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
313
284
```
314
285
315
286
### User Stories
@@ -433,6 +404,65 @@ is to run his team's autodiagnose script:
433
404
434
405
## Design Details
435
406
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
+
436
466
### Test Plan
437
467
438
468
In addition to standard unit tests for ` kubectl ` , the ` debug ` command will be
@@ -446,7 +476,7 @@ test prior to Alpha -> Beta graduation.
446
476
#### Alpha -> Beta Graduation
447
477
448
478
- [ ] 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
450
480
a running pod using Ephemeral Containers.
451
481
- [ ] A survey sent to early adopters doesn't reveal any major shortcomings.
452
482
- [ ] 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._
703
733
- * 2019-12-05* : Updated KEP for expanded debug targets.
704
734
- * 2020-01-09* : Updated KEP for debugging nodes and mark implementable.
705
735
- * 2020-01-15* : Added test plan.
736
+ - * 2020-09-20* : Updated to reflect actual implementation details.
706
737
707
738
## Drawbacks
708
739
0 commit comments