kubectl attach: Unable to use a TTY - container es-node did not allocate one

旧巷老猫 提交于 2020-01-01 08:19:09

问题


I am trying to attach to a running container in Kubernetes, however I get the error message below.

>kubectl attach -it es-client-2756725635-4rk43 -c es-node
Unable to use a TTY - container es-node did not allocate one
If you don't see a command prompt, try pressing enter.

How do I enable a TTY in my container yaml?


回答1:


In order to have proper TTY and stdin when doing attach:

kubectl attach -it POD -c CONTAINER

The container must be configured with tty: true and stdin: true. By default both of those values are false: https://kubernetes.io/docs/api-reference/v1.5/#container-v1

Example Pod:

spec:
      containers:
      - name: web
        image: web:latest
        tty: true
        stdin: true



回答2:


The reason why it's failiing is because you're not passing the bash argument. This causes a failure when trying to create a tty connection.

Please try:

kubectl exec -it [POD-NAME] -c [CONTAINER-NAME] bash



回答3:


For Windows, MINGW64 (git bash) does not seem to work, but PowerShell does!

kubectl exec -it abc-deployment-5d64659ff8-8tnnb -- /bin/bash
root@abc-deployment-5d64659ff8-8tnnb:/#



回答4:


Whatever I did, it didn't work, tty command would always return not a tty response and exit non-0, i.e. nothing that require tty would work on my terminal.

I'm making an ephemeral workstation with persistent disk as my $HOME with Ubuntu Bionic Beaver on GKE.

Since I had brew installed in my PD mounted $HOME and brew was in my $PATH, following worked for me:

brew install tmux
tmux new -d -s <some arbitrary session name here> ### i.e.> tmux new -d -s tty
tmux ls # Lists your sessions
tmux a  # Attach to first available session

Then inside tmux:
$ tty
Voila
/dev/pts/0

My agnoster is b0rkz but now I can do stuff that prompts for interactive password entry, i.e. gcloud auth.

PS: For those curious, I mounted /etc/shadow, /etc/group, /etc/passwd into /etc with configmap



来源:https://stackoverflow.com/questions/39886146/kubectl-attach-unable-to-use-a-tty-container-es-node-did-not-allocate-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!