3

v1.5.1使用该kubectl run/exec -i --tty功能运行时出现问题。

发送数据时连接不会中断。因此,当我启动一个交互式容器会话时,使用一个不时输出某些内容的脚本,它似乎可以工作。

基于此,我创建了一个令人讨厌的解决方法来让我的容器会话继续进行,而无需我的交互。这些会话过早终止真的很烦人。它们会留下垃圾,如果您连接到正在运行的生产容器,则需要清理这些垃圾。

解决方法(作为后台进程每 59 秒打印一个空格字符到 STDERR):

# within your container session
$ while :; do sleep 59; echo -n ' ' >&2; done &

当我不启动这样的脚本时,请参阅以下输出。 它表明交互式会话在约 2 分钟内过早终止。

如果您使用此功能来调试正在运行的应用程序和容器安装,这真的很烦人。

$ time kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
Waiting for pod default/busybox to be running, status is Pending, pod ready: false
If you don't see a command prompt, try pressing enter.
/ # Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
Waiting for pod default/busybox to terminate, status is Running
error: timed out waiting for the condition

real    2m4.657s

从此Github 问题重新发布。

4

1 回答 1

0

我现在已经解决了这个问题。该问题是由通过 AWS LoadBalancer(ELB 或 ALB)提供服务的 Kubernetes API 引起的。那些在超时后终止连接,导致kubectl与 Kubernetes API 服务器断开连接。

这本身不是 Kubernetes 问题,它与您如何为最终用户提供 Kubernetes API 服务器有关。在这种情况下,通过负载均衡器。

快速解决方法:增加超时时间或不时通过线路发送数据以保持连接打开。

于 2020-03-12T10:50:47.803 回答