kubernetes:如何从附加的 pod 中分离

kubernetes : How to deattach from an attached pod

我有一个 运行 pod,我用 kubectl attach -ti mypod 给他输入。

但是,我想从我的 pod 中“脱离”并 return 回到我的终端而不终止我的 pod。 我该怎么做?

来自 kubernetes docs:

To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.


更新:

根据@Abdelghani 的反馈:

For the record, this does not work if tty is set to false in the container. I didnt find another way to detach other than killing the pod/container.

您可以在不杀死 pod 的情况下杀死 kubectl attach -it .. 进程:

host$ kubectl attach -it podname
pod$ do something in pod

打开另一个终端,找到你的kubectl attach命令,然后杀掉它,比如:

host$ ps x | grep "kubectl attach"
> 1234 pts/22   Sl+    0:00 kubectl attach -it podname
host$ kill 1234