kubernetes: kubectl exec -it fails with "Unable to use a TTY" and never get a prompt
Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.): No
What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.):
Unable to use a TTY
Is this a BUG REPORT or FEATURE REQUEST? (choose one):
BUG REPORT
Kubernetes version (use kubectl version
):
root@kube-master:~# kubectl version
Client Version: version.Info{Major:“1”, Minor:“4+”, GitVersion:“v1.4.7-beta.0.2+1ef121737093fd-dirty”, GitCommit:“1ef121737093fdefada11034782d235a205f567f”, GitTreeState:“dirty”, BuildDate:“2016-11-25T03:02:28Z”, GoVersion:“go1.7.3 ibm-1.7”, Compiler:“gc”, Platform:“linux/ppc64le”}
Server Version: version.Info{Major:“1”, Minor:“4+”, GitVersion:“v1.4.7-beta.0.2+1ef121737093fd-dirty”, GitCommit:“1ef121737093fdefada11034782d235a205f567f”, GitTreeState:“dirty”, BuildDate:“2016-11-25T03:02:28Z”, GoVersion:“go1.7.3 ibm-1.7”, Compiler:“gc”, Platform:“linux/ppc64le”}
root@kube-master:~#
Environment:
- Cloud provider or hardware configuration: hardware configuration
- OS (e.g. from /etc/os-release):
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial
- Kernel (e.g.
uname -a
): Linux kube-master 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:38:24 UTC 2016 ppc64le ppc64le ppc64le GNU/Linux - Install tools:
- Others:
What happened:
kubectl exec -it <pod_name> – /bin/bash fails with error “Unable to use a TTY” and never get a prompt
root@kube-master:~# kubectl exec -it my-nginx-2833891535-ycsq2 -- /bin/bash
Unable to use a TTY - input is not a terminal or the right kind of file
=============> never get a prompt
What you expected to happen:
Could use kubectl exec -it <pod_name> – /bin/bash to get the shell prompt of the POD.
How to reproduce it (as minimally and precisely as possible):
- Install Kubernetes 1.4.7
- Deploy an application
- Run kuectl exec -it <pod_name> – /bin/bash
Anything else do we need to know:
I could use docker exec -it <container_name> /bin/bash to get the prompt, but kubectl exec does not work.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 22
- Comments: 73 (8 by maintainers)
I had the same issue when trying to pipe to xargs:
kubectl get pods -n foobar | grep baz | awk '{print $1}' | xargs -J % kubectl exec -it -n foobar % /bin/bash
Fixed it by passing
-o
toxargs
. Fromman xargs
:Hope this helps someone!
taking out -t flag from the command solved it for me.
Windows Users: use “Windows PowerShell”, not “Git Bash”
Same issue but
winpty kubectl.exe exec -it <pod> -- bash
worked for me as a workaround - see https://github.com/Microsoft/WSL/issues/2271#issuecomment-317006437.I am facing the same problem while executing through Jenkins terminal.
Use: $> winpty kubectl exec -it <pod-name> bash
Have the same issue using MobaXterm (cgywin)
Facing the same issue on Git Bash Terminal on Windows 7:
kubectl exec -it <pod_name> bash
But, the same works on cmd, powershell and Docker Terminal.
Hi @ligc - Have you tried:
kubectl exec -it my-nginx-2833891535-ycsq2 /bin/bash
orkubectl exec -it my-nginx-2833891535-ycsq2 sh
? That’s what I would typically use and it works fine 😃use
xargs -o
option to Reopen the stdin as/dev/tty
in the child process before executing the command.for example:
Getting the same while trying to use an alias:
then:
same issue with me as well
$ kubectl exec -it nfs-server -n testnm – bash Unable to use a TTY - input is not a terminal or the right kind of file
but when I create alias it worked alias kubectl=‘winpty kubectl’
$ kubectl exec -it nfs-server -n testnm – bash bash-5.0#
If you don’t like solution from @nick-pap you can define alias:
$> alias kubectl='winpty kubectl'
and then use$> kubectl exec -it test sh
as usual.Git bash works like Unix shell and it uses stdin and stdout streams to communicate with kubectl, however in Windows with Git bash you are using actually kubectl.exe that expects Windows console and not Unix streams. Winpty solves this problem.
If you want to make the change permanent put the alias into ~/.bash_profile file.
@albertlr As I mentioned this is probably not a Kubernetes bug. The terminal package within the docker engine is currently being incapable of detecting fake terminals like Git bash and Cygwin terminal. This issue does not reproduce on
cmd.exe
because it is a real terminal, for which GetConsoleMode returns TRUE. Adding a special detection logic like this one to the docker engine will fix the issue but there is nothing that can be done here except removing the check altogether.Same issue using MobaXterm (cygwin) and
got the same problem with kubectl on cygwin, i dont get a prompt but the shell gives response to commands. any ideas how to fix this?
{ ~ } » kubectl exec -it iscsi-provisioner-7f46d96b8c-jt6rc – /bin/sh ~ 130 Unable to use a TTY - input is not a terminal or the right kind of file ls -al /root total 36 dr-xr-x— 2 root root 4096 Sep 11 2017 . drwxr-xr-x 1 root root 4096 Jul 11 22:49 … -rw-r–r-- 1 root root 18 Dec 29 2013 .bash_logout -rw-r–r-- 1 root root 176 Dec 29 2013 .bash_profile -rw-r–r-- 1 root root 176 Dec 29 2013 .bashrc -rw-r–r-- 1 root root 100 Dec 29 2013 .cshrc -rw-r–r-- 1 root root 129 Dec 29 2013 .tcshrc -rw------- 1 root root 3407 Sep 11 2017 anaconda-ks.cfg -rw------- 1 root root 3221 Sep 11 2017 original-ks.cfg cat /root/.bashrc .bashrc
User specific aliases and functions
alias rm=‘rm -i’ alias cp=‘cp -i’ alias mv=‘mv -i’
Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi