Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding ``stdin: true tty: true`` on a kubernetes container?

Tags:

I have been readying here and there online but the answer does not come thoroughly explained. I hope this question here if answered, can provide an updated and thorough explanation of the matter.

Why would someone define a container with the following parameters:

stdin: true
tty: true

Also if

`docker run -it`

bind the executed container process to the calling client stdin and tty, what would setting those flag on a container bind its executed process it to ?

I could only envision one scenario, which is, if the command is let say bash, then you can attach to it (i.e. that bash running instance) later after the container is running.

But again one could just run docker run it when necessary. I mean one launch a new bash and do whatever needs to be done. No need to attach to a running one

So the first part of the question is:

a) What is happening under the hood ?

b) Why and when to use it, what difference does it make and what is the added value ?

like image 376
MaatDeamon Avatar asked Jan 27 '21 09:01

MaatDeamon


1 Answers

AFAIK, setting stdin: true in container spec will simply keep container process stdin open waiting for somebody to attach to it with kubectl attach.

As for tty: true - this simply tells Kubernetes that stdin should be also a terminal. Some applications may change their behavior based on the fact that stdin is a terminal, e.g. add some interactivity, command completion, colored output and so on. But in most cases you generally don't need it.

Btw kubectl exec -it POD bash also contains flags -it but in this case this really needed because you're spawning shell process in container's namespace which expects both stdin and terminal from user.

like image 56
Vasili Angapov Avatar answered Oct 11 '22 07:10

Vasili Angapov