Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl exec fails with the error "Unable to use a TTY - input is not a terminal or the right kind of file"

I am running a jenkins pipeline with the following command:

kubectl exec -it kafkacat-5f8fcfcc57-2txhc -- kafkacat -b cord-kafka -C -t BBSim-OLT-0-Events -o s@1585031458

which is running fine on the terminal of the machine the pipeline is running on, but on the actual pipeline I get the following error: "Unable to use a TTY - input is not a terminal or the right kind of file"

Any tips on how to go about resolving this?

like image 934
Shrey Baid Avatar asked Mar 24 '20 06:03

Shrey Baid


People also ask

Why can't kubectl exec detect a TTY file?

Apparently this is a docker bug. kubectl exec internally invokes the terminal component included in the docker engine but their implementation (using GetConsoleMode to judge if a file handle is a tty) does not detect fake Windows terminals including Git bash and Cygwin bash as a valid tty.

Does kubectl Exe work in WSL?

Other things with kubectl.exe work quite well in WSL. kubect exec -it in windows works well of cource. Please include an strace. Sorry, something went wrong. Sorry, something went wrong. You had known, reference to kubernetes/kubernetes#37471.

Why is MySQL-T not working with terminal interface?

In the last two cases, you get this behavior because mysql as well as shell were not treating the input as a tty and thus did not use tty specific behavior like masking the input or coloring the output. Show activity on this post. -t option pulls in a terminal interface driver, that works on top of STDIN/STDOUT.

Does kubectl have a TTY?

@whitecolor - Wsltty or wsl-terminal are another story :). I mean... kubectl.exe is a windows program and windows does not have a TTY like unix. Winpty has another purpose, I heard. Of course, wheither WSL support tty enough or not is a different issue. Sorry, something went wrong.


4 Answers

For windows git bash:

alias kubectl='winpty kubectl'
$ kubectl exec -it <container>

Or just use winpty before the desired command.

like image 154
4F2E4A2E Avatar answered Oct 27 '22 00:10

4F2E4A2E


For Windows GitBash users, use Powershell and NOT GitBash

like image 42
Ryan Augustine Avatar answered Oct 27 '22 00:10

Ryan Augustine


When the flags -it are used with kubectl exec, it enables the TTY interactive mode. Given the error that you mentioned, it seems that Jenkins doesn't allocate a TTY.

Since you are running the command in a Jenkins job, I would assume that your command is not necessarily interactive. A possible solution for the problem would be to simply remove the -t flag and try to execute the following instead:

kubectl exec -i kafkacat-5f8fcfcc57-2txhc -- kafkacat -b cord-kafka -C -t BBSim-OLT-0-Events -o s@1585031458
like image 40
foo0x29a Avatar answered Oct 27 '22 01:10

foo0x29a


Remove the -t option. That requests a TTY, which as you noted does not exist in Jenkins.

like image 42
coderanger Avatar answered Oct 27 '22 00:10

coderanger