kubernetes: Initial terminal dimensions for `kubectl exec` are not set correctly

Is this a BUG REPORT or FEATURE REQUEST?: BUG REPORT

Uncomment only one, leave it on its own line:

/kind bug

/kind feature

What happened: kubectl exec -it used to set the terminal dimensions correctly. Now, they’re only set correctly if you resize the terminal. My theory is that this regressed due to underlying architectural changes in docker and how it creates exec processes, but I’m not 100% sure about that.

What you expected to happen: When you kubectl exec -it and inspect $COLUMNS or $LINES, the variables should reflect the current terminal size.

How to reproduce it (as minimally and precisely as possible):

  1. resize your terminal to something that is not the standard 80x24
  2. kubectl run --restart Never --image nginx nginx
  3. kubectl exec -it nginx bash
  4. echo $COLUMNS

Anything else we need to know?: Forked from #13585.

Environment:

  • Kubernetes version (use kubectl version): commit afc4506
  • OS (e.g. from /etc/os-release): Fedora 25
  • Kernel (e.g. uname -a): 4.8.6-300.fc25.x86_64
  • Others: docker-1.12.6-6.gitae7d637.fc25.x86_64

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (10 by maintainers)

Commits related to this issue

Most upvoted comments

This is still an issue. Is it being looked into?

Stock Ubuntu 18, and at our company we also use a proprietary build of Fedora 27, both with the same results.

With that said - Docker exec reports it fine, but opening say, Vim in a container deployed in Kubernetes vim gets maybe a 4th of the screen.

There was a provided script kshell in the previous thread:

if [ "$1" = "" ]; then
  echo "Usage: kshell <pod>"
  exit 1
fi
COLUMNS=`tput cols`
LINES=`tput lines`
TERM=xterm
kubectl exec -i -t $1 env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM bash

That makes the terminal report everything correctly, but stock kubectl does not.

Hmm, I still got the same result.

$ kubectl exec -it nginx bash
root@nginx:/# echo $COLUMNS
80

Environment:

Kubernetes version (use kubectl version):

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:21:50Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:13:31Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

OS (e.g. from /etc/os-release): macOS Sierra 10.12.6 Kernel (e.g. uname -a):

Linux nginx 4.9.87-linuxkit-aufs #1 SMP Fri Mar 16 18:16:33 UTC 2018 x86_64 GNU/Linux

(Ran uname -a in nginx pod) Others: Docker for Mac Version 18.05.0-ce-mac66 (24545) edge channel

Also still having the same issue.

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"dd5e1a2978fd0b97d9b78e1564398aeea7e7fe92", GitTreeState:"clean", BuildDate:"2018-04-19T00:05:56Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:05:37Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

What happens if you do a normal kubectl exec -it, then resize the window? Does it report correctly after the resize?