我正在尝试调试为什么一个完美工作的部署的服务没有响应(连接被拒绝)。
我已经反复检查了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(顺便说一句,如果我尝试卷曲服务,也会发生同样的情况)
然而,如果我直接将端口转发到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我还检查了当我从服务中使用选择器时是否获得了pods (我从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我不明白为什么端点在使用端口转发获得有效响应时会拒绝连接。还有什么我需要检查的吗?
发布于 2019-06-25 16:58:01
好了,原来这个特定的服务只在默认情况下监听localhost:
$ netstat -tunap | grep LISTEN
tcp 0 0 127.0.0.1:4180 0.0.0.0:* LISTEN 1/oauth2_proxy我必须添加一个参数(-http-address=0.0.0.0:4180)来告诉它监听0.0.0.0
https://stackoverflow.com/questions/56749417
复制相似问题