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):

  1. Install Kubernetes 1.4.7
  2. Deploy an application
  3. 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)

Most upvoted comments

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 to xargs. From man xargs:

Reopen stdin as /dev/tty in the child process before executing the command. 
This is useful if you want xargs to run an interactive application.

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)

> kubectl exec --namespace=default -it hello-world-65c6847588-qnhqd /bin/sh
Unable to use a TTY - input is not a terminal or the right kind of file

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 or kubectl 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:

kubectl get pods | perl -alne ‘print $F[0] if $F[0] =~ /toolkit/’ | xargs -o -I {} kubectl exec -it {} -c toolkit sh

Getting the same while trying to use an alias:

alias kexecp='{ pod=$(cat -); k exec -it $pod --context=prod -- sh; }<<<'

then:

% kexecp some-app
Defaulting container name to some-app.
Use 'kubectl describe pod/some-app' to see all of the containers in this pod.
Unable to use a TTY - input is not a terminal or the right kind of file

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

> kubectl version
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.0", GitCommit:"0ed33881dc4355495f623c6f22e7dd0b7632b7c0", GitTreeState:"clean", BuildDate:"2018-09-27T17:05:32Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"windows/amd64"}
> uname
CYGWIN_NT-10.0-WOW
>  uname -r
2.8.2(0.313/5/3)

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