Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 960
Ameo Avatar asked Jun 20 '18 03:06

Ameo


2 Answers

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)

like image 192
d0bry Avatar answered Sep 28 '22 17:09

d0bry


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]

like image 21
Daein Park Avatar answered Sep 28 '22 18:09

Daein Park