kubernetes / kubernetes/kubectl
Feature Request: detach-keys option/setting for pod terminal
- Dominant language
- Go
- Stars
- 3.3k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
_This is a revival of #693 which was sort of duplicated by #878 but both went stale before being addressed. #878 labeled this behavior a bug and put it on the backlog. I consider it a feature request, but am happy to let SIGCLI decide._
_See Update 2023-04-04 below_
`kubectl run -it`, `kubectl exec -it`, and `kubectl attach -it` connect to a Docker container in a manner parallel to `docker run -it` and `docker attach`. All these commands by default listen for the key sequence `ctrl-p,ctrl-q` to cause the command to detach from the container. However, unlike `kubectl`, the `docker` commands have a [`--detach-keys` option] and [configuration property](https://docs.docker.com/engine/reference/commandline/cli/#configjson-properties) to allow you to specify an alternate key sequence to use instead of the default. `kubectl` is missing this option. Please implement it.
The default is problematic with `bash` because by default, `ctrl-p` on the `bash` command line brings up the previous command from the history list. Users typing `ctrl-p` once expect to see the previous command, but get nothing until they type another character, because the `ctrl-p` (being the first character in a potential 2-character command) is held back until the next character is sent. If the next character is `ctrl-q` the connection is closed and the container never sees the `ctrl-p`. If the next character is something else, then the `ctrl-p` and the next character are sent as soon as the second character is typed. If that character is `ctrl-p`, then the user will get the to see the command before the previous command, as they have just typed `ctrl-p,ctrl-p`. So getting to the immediately previous command requires typing `ctrl-p` followed by some other character that will not alter the command line. This is annoying at best.
Whatever issues people may have with the default detach key sequence in `docker` are alleviated by the presence of the `--detach-keys` option and the `detachKeys` property of the `docker` configuration. However `kubectl` does not have this option.
Please add a `--detach-keys` option that operates the same way as `docker --detach-keys` does.
# Update 2023-04-04
Although the latest (v1.26) documentation still [says you can detach using Ctrl+P,Ctrl+Q](https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/#docker-attach), this no longer seems to be the case. It seems you have to kill the attached process or close the connection with Ctrl+D. Why this is or what changed is not documented. So this is now also a request to update the documentation to reflect current behavior and to show the recommended way to end a session.
See also:
- https://github.com/kubernetes/kubernetes/issues/71765
- https://github.com/kubernetes/kubernetes/issues/79110
- https://stackoverflow.com/a/66276082
Contributor guide
Research direction
Start by tracing the kubectl run, exec, and attach terminal paths and compare their detach handling with Docker's --detach-keys behavior. Check the linked documentation and related issues to establish the current Ctrl+P,Ctrl+Q and Ctrl+D behavior. Done means the requested option works consistently and the documentation describes the supported way to detach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- cli, documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100