Just now I ran into an IPython interpreter inside a Docker container inside Kubernetes misbehaving:

After starting ipython inside a kubectl for a second time, IPython wouldn't show the input prompt. It only showed the output prompt.

Turns out it was due to the terminal settings. For some reasons, after logging out of kubectl exec, the next exec would get 0 rows and 0 columns; as if someone had run stty rows 0 on the terminal. And of course, this wasn't reliably reproducible, but happened often enough.

This already appeared to mangle the Bash shell somewhat, but it was still usable, and perfectly mitigatable through a bit of extra environment:

$ kubectl exec -it my-pod-xxx env LINES=$LINES COLUMNS=$COLUMNS bash

But that only fixed the shell, not the IPython interpreter. Doing a reset on the original shell fixes things. But for a more soft approach that actually works, I resorted to this:

$ kubectl exec -it my-pod-xxx -- sh -c "stty rows $LINES cols $COLUMNS && exec bash"

A few more characters to type, but it does the trick. See stty -a for the current values.

terminal k8s stty