【问题标题】:Kubernetes api server drop requests from a pod causing dial error来自 pod 的 Kubernetes api 服务器丢弃请求导致拨号错误
【发布时间】:2016-03-11 10:12:24
【问题描述】:

我已将 kubernetes 升级到 1.1.7 版,并从我的一个 pod 中收到此错误,该 pod 经常调用 k8s ApiServer 以检查所有其他 pod 的活动状态。

Error #01: Get http://[api-server]:8080/api/v1/namespaces/production/pods?labelSelector=app%3Dworkflow-worker-mandrill-hook-handler: dial tcp [api-server]:8080: connect: cannot assign requested address

请求以大约 80 个请求/秒的速率发送。在出现该错误时,我仍然能够从本地调用该 API。重新启动 pod 解决了问题,但第二天又发生了。似乎 apiserver 正在阻止该 pod 以避免 DOS?

我正在使用 docker 版本 Docker version 1.7.1, build 2c2c52b-dirty 和 CoreOS v773.0.0

Linux ***** 4.1.5-coreos #2 SMP Thu Aug 13 09:18:45 UTC 2015 x86_64 Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz GenuineIntel GNU/Linux

Kubernetes api 服务器错误日志:

I0306 07:32:13.087599       1 logs.go:40] http: TLS handshake error from ***:60033: EOF
I0306 07:32:14.596398       1 logs.go:40] http: TLS handshake error from ***:57257: EOF
I0306 07:32:15.126962       1 logs.go:40] http: TLS handshake error from ***:60035: EOF
I0306 07:32:15.136445       1 logs.go:40] http: TLS handshake error from ***:60054: EOF
I0306 07:32:15.210656       1 logs.go:40] http: TLS handshake error from ***:45384: EOF
I0306 07:32:15.215155       1 logs.go:40] http: TLS handshake error from ***:45385: EOF
I0306 07:32:15.253877       1 logs.go:40] http: TLS handshake error from ***:37527: EOF
I0306 07:32:15.265899       1 logs.go:40] http: TLS handshake error from ***:57258: EOF
I0306 07:32:15.272564       1 logs.go:40] http: TLS handshake error from ***:57249: EOF
I0306 07:32:15.282808       1 logs.go:40] http: TLS handshake error from ***:59928: EOF

dmesg 在主节点:

[Sun Mar  6 07:32:04 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:04 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:04 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:04 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:04 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:15 2016] net_ratelimit: 34 callbacks suppressed
[Sun Mar  6 07:32:15 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:18 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:18 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:18 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:21 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:21 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:21 2016] TCP: too many orphaned sockets
[Sun Mar  6 07:32:29 2016] TCP: too many orphaned sockets

【问题讨论】:

  • 您有多少个 Pod 同时尝试 80 qps?您的 pod 是否有可能泄漏套接字,导致 kube-apiserver 的系统用完可用的套接字?请注意,如果您有非标准 kubernetes 设置,则需要增加 kube-apiserver 的 FD 数量(例如,ulimit)。
  • 另外,请注意,不幸的是,列表操作现在很昂贵,我预计至少更大的集群可能无法处理 80qps 的 pod 列表。但是,您可以考虑创建一个服务或复制控制器 - 根据您正在做什么,这些对象可能会为您完成。

标签: sockets kubernetes coreos


【解决方案1】:

经过 4 小时的调查,原来是因为我的应用程序查询了 k8s api 服务器。它是用 Golang 编写的,并使用“gorequest”库向 api 服务器调用 REST api。

gorequest 在发送后没有关闭请求,即使我在代码中明确关闭了它。而且很难检查打开连接的数量,因为它在 Docker 容器中运行。通常通过命令ls /proc/PID/fd | wc -l 签入主机就足够了,但这次我必须访问容器内部进行检查。所以我尝试使用“http”库而不是 gorequest,它解决了问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多