kubernetes: kubectl exec -i exits prematurely

With the current Git version of kubectl (see below), I cannot get an interactive shell in a container:

kubectl exec -ti single-container-pod bash

just exits after a couple of seconds, without echoing any TTY input.

Similarly,

cat large-file | kubectl exec -i single-container-pod -- bash -c "cat > /tmp/test && ls -l /tmp/test"

shows that in many cases, the file is not completely transferred. “large-file” was 1MB in my case, with 6Mbit upload rate.

Client Version: version.Info{Major:“1”, Minor:“2+”, GitVersion:“v1.2.0-alpha.1.1092+b8aabbbf4f92f0”, GitCommit:“b8aabbbf4f92f006cd1a118dbfd14d97bb996478”, GitTreeState:“clean”}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 2
  • Comments: 49 (34 by maintainers)

Most upvoted comments

This is usually the load balancer timeout in front of an apiserver. Check the timeout from the ELB

Having the same problem here. Running v1.5.1 Connections do not get interrupted when data is being sent. So when I launch an interactive container session, with a script that outputs something every now and then, it seems to work.

Based on that, I created a nasty workaround to keep my container sessions going, without my interaction. It is really annoying that these sessions terminate prematurely. They leave garbage behind, that needs to cleaned up in case you are attaching to a running production container.

The workaround (print a space-character to STDERR every 59 seconds as a background process):

# within your container session
$ while :; do sleep 59; echo -n ' ' >&2; done &

See the following output, when I do not launch such a script. It demonstrates that an interactive session terminates prematurely within ~ X minutes.

This is really annoying if you are leveraging this functionality to debug running applications and container installations.

$ time kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
Waiting for pod default/busybox to be running, status is Pending, pod ready: false
If you don't see a command prompt, try pressing enter.
/ # Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
error: timed out waiting for the condition

real	2m4.657s

I’m seeing something similar. kubernetes running in AWS EC2. If I kubectl exec <pod-name> -i -t -- ash, I get booted after about 60 seconds of no activity. Which is annoyingly short for an interactive session. Is this configurable?

Some message on disconnect might be nice as well. The only visible indication is that my shell prompt changes, and it can be easy to not realize that I’m now back at my local host, and not on the kube pod.

I also noticed another downside to this:

Whatever we are doing using exec at the time of the disconnect keeps running in the background: meaning we sometimes use a console program to enter our production code, which consumes some amount of memory inside the pod. After a day of disconnects, we have 20 to 30 running unused consoles , and a pod that has reached is memory limit, degrading performance of the actual application running inside the pod.

A good old kill -9 after exec’ing as sh solves this problem, but it’s annoying nonetheless.