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?
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
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
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:/#
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
you can add a shell container ,like this.
then you can use
kubectl attach -it nginx -c shell
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
shareProcessNamespace: true
containers:
- name: nginx
image: nginx
- name: shell
image: busybox
stdin: true
tty: true