How can I exit a `kubectl exec` command that has frozen due to a network error?

6/20/2018

Sometimes, I'll have a terminal tab with kubectl exec bash running in it to check on a container or tail a log file. When I shut my laptop, turn on my VPN, or just lose Wi-Fi for a second, that terminal can sometimes freeze and leave me unable to exit it without closing the terminal tab or killing the process manually.

I know that SSH sessions have an enter-tilda-period key combo that lets you quit in just this situation, but this doesn't seem to work for kubectl exec. Is there any similar way to accomplish this in this situation?

-- Ameo
docker
kubectl
kubernetes

2 Answers

6/20/2018

It is not clear what is the root of the problem causing abnormal hang ups of kubectl exec command.

Getting back to your question, you can force to drop the connection and return control of (docker) terminal back to your hands by setting: --request-timeout=<value> to the kubectl command line:

kubectl exec --request-timeout=5s bash

It is possible to force termination of kubectl exec by sending -9 signal using kill command.

kill -9 $(pidof kubectl)

-- d0bry
Source: StackOverflow

6/20/2018

I think you can try as follows.

kubectl --request-timeout=10s

[0][https://kubernetes.io/docs/reference/kubectl/kubectl/#options]

Or you might need to implement functions like below. [1]

[1][http://fibrevillage.com/sysadmin/236-how-to-timeout-a-command-in-linux-shell]

-- Daein Park
Source: StackOverflow