How to prevent kubectl interactive shell from being closed after few minutes (increase timeout) / or terminal from dying?

7/29/2019

I run this command:

kubectl run my-shell --rm -it --image alpine -- sh

It all works fine, but after a few minutes of inactivity the shell closes on it's own and my terminal hangs as well, so that kubectl does not remove the pod since it cannot complete.

So I am wondering, is it possible to increase the timeout before this happens, I have not found this in the documentation?

P.S. Help on preventing terminal hanging is appreciated as well, I am using ordinary windows command line.

P.P.S. This is happening in AKS, as @wolmi suggested it might be relevant.

-- Ilya Chernomordik
azure-kubernetes
kubectl
kubernetes

2 Answers

8/7/2019

Hi I didn't found better solution than keeping some process running inside the container like:

kubectl run ala --rm -it --image alpine --generator=run-pod/v1 -- sh -c 'while sleep 120; do date; done'

Please refer also to the community post regarding TCP keepalive parameters - on the server side:

net.ipv4.tcp_keepalive_time = 200
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_intvl = 50

Hope this help.

-- Hanx
Source: StackOverflow

7/29/2019

Add the --generator flag:

kubectl run my-shell --rm -it --image alpine --generator=run-pod/v1 -- sh

I tried with no problem during more than 20min idle.

By default the run command uses --generator=deployment/apps.v1beta1 that is deprecated and generated a different yaml.

-- wolmi
Source: StackOverflow