BEPP
BEPP

Reputation: 955

Killing kubectl exec command from master node doesn't kill the command running inside pod

I ran kubectl exec -it pod_XXXX -- top command from my master node. Then killed the kubectl exec process by sudo kill -9 <pid_of_kubectl> command from another terminal.

 kubectl exec -it pod_XXXX -- top
 sudo kill -9 <pid_of_kubectl_exec_command>

Inside POD the top command keeps running.This issue is not seen when i press crtl+c to terminate the kubectl exec. Is it expected behavior?

Upvotes: 0

Views: 2215

Answers (1)

Shahed Mehbub
Shahed Mehbub

Reputation: 581

By running kubectl exec -it you're connecting/streaming your terminal to the pod terminal so that if you type anything to your terminal, streams to the pod terminal. That's why when you run kubectl exec -it pod_XXXX -- top on your terminal, it worked as expected. Remember, the POD's termial is running the top interface, not yours.

So, when you type sudo kill -9 pid_of_kubectl_exec_command, it kills the connection between your terminal and the POD's terminal. So, the process inside the POD's terminal keeps running.

When you press ctrl+c from your terminal, it streams ctrl+c to the POD terminal, that's why the top terminates instantly.

Upvotes: 6

Related Questions