【发布时间】:2022-03-04 16:24:19
【问题描述】:
我正在尝试调试为什么一个完美运行的部署的服务没有响应(连接被拒绝)。
我检查了 port 和 targetPort 是否匹配(4180 用于容器,80 用于服务)
当我列出我的端点时,我得到以下信息:
$ kubectl get endpoints
NAME ENDPOINTS AGE
kubernetes 10.40.63.79:443 82d
oauth2-proxy 10.40.34.212:4180 33s // <--this one
并且来自在同一命名空间中运行的 pod:
# curl 10.40.34.212:4180
curl: (7) Failed to connect to 10.40.34.212 port 4180: Connection refused
(顺便说一句,如果我尝试 curl 服务也会发生同样的情况)
然而,如果我直接转发到 pod,我会得到响应:
$ kubectl port-forward oauth2-proxy-559dd9ddf4-8z72c 4180:4180 &
$ curl -v localhost:4180
* Rebuilt URL to: localhost:4180/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 4180 (#0)
> GET / HTTP/1.1
> Host: localhost:4180
> User-Agent: curl/7.58.0
> Accept: */*
>
Handling connection for 4180
< HTTP/1.1 403 Forbidden
< Date: Tue, 25 Jun 2019 07:53:19 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
<
<!DOCTYPE html>
// more of the expected response
* Connection #0 to host localhost left intact
我还检查了我在使用服务中的选择器时是否获得了 pod(我从kubectl describe svc oauth2-proxy 中看到的内容复制粘贴了它):
$ kubectl describe svc oauth2-proxy | grep Selector
Selector: app.kubernetes.io/name=oauth2-proxy,app.kubernetes.io/part-of=oauth2-proxy
$ kubectl get pods --selector=app.kubernetes.io/name=oauth2-proxy,app.kubernetes.io/part-of=oauth2-proxy
NAME READY STATUS RESTARTS AGE
oauth2-proxy-559dd9ddf4-8z72c 1/1 Running 0 74m
我不明白为什么端点拒绝连接,而使用端口转发得到有效响应。还有什么我应该检查的吗?
【问题讨论】:
-
可以分享一下部署和服务yaml吗?
-
感谢回复,终于找到问题所在了,我不知道为什么开发者默认选择只在localhost上监听,但至少他们在容器中有netstat来解决这个问题:- )
标签: kubernetes