kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.89k stars 924 forks source link

Add `--rm` flag to `kubectl debug` to remove debug pod on exit #1681

Open tksm opened 2 hours ago

tksm commented 2 hours ago

What would you like to be added:

I would like to add the --rm flag to kubectl debug, similar to the flag in kubectl run and docker run, which allows automatic deletion of the debug pod upon exit. Since ephemeral containers cannot be removed, this flag would only apply when debugging a node or a pod with --copy-to.

I have already opened a PR for this feature, as its implementation is small: https://github.com/kubernetes/kubernetes/pull/129046

Why is this needed:

kubectl debug -it node is very useful replacement for ssh, but I often forget to remove completed debug pods. These completed pods are generally not useful, and even the official documentation includes a step for "Cleaning up".

$ kubectl get pods
NAME                           READY   STATUS      RESTARTS   AGE
node-debugger-minikube-4gq42   0/1     Completed   0          74s
node-debugger-minikube-8xrvr   0/1     Completed   0          31s
node-debugger-minikube-hscjt   0/1     Completed   0          20s
..
k8s-ci-robot commented 2 hours ago

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
ardaguclu commented 1 hour ago

Although at first sight it looks reasonable, each new flag puts kubectl debug under a risk of unusability that kubectl run already experiences due to plenty of flags. As already stated in the description, this new flag won't work on ephemeral containers anyway. In my opinion, hurting the usability for a new flag far outweighs the benefits we get and we should be reluctant to add this flag.