“curl:(8)奇怪的服务器回复”从kubernetes

我正在尝试从Kubernetes内运行的容器中使用Python Rest API调用。 我能够使用吊舱内的服务

*curl http://localhost:5002/analyst_rating -v * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 5002 (#0) > GET /analyst_rating HTTP/1.1 > Host: localhost:5002 > User-Agent: curl/7.47.0 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Content-Type: application/json < Content-Length: 37 < Server: Werkzeug/0.12.2 Python/2.7.12 < Date: Tue, 05 Dec 2017 17:02:00 GMT < { "Analyst Rating": "Hello World" * Closing connection 0* 

当我从群集外部运行curl命令时,出现以下错误:

  curl -I http://184.173.44.62:30484/analyst_rating -v * Trying 184.173.44.62... * TCP_NODELAY set * Connected to 184.173.44.62 (184.173.44.62) port 30484 (#0) > HEAD /analyst_rating HTTP/1.1 > Host: 184.173.44.62:30484 > User-Agent: curl/7.54.0 > Accept: */* > * Closing connection 0 curl: (8) Weird server reply 

我的群集IP是184.173.44.62,我的服务节点端口是30484.我能够build立连接,但无法收到任何回应。 此外,我已经检查了吊舱内,我没有得到任何GET请求。

另外,以下是我的部署信息:

 kubectl describe deployment Name: sunlife-analystrating-deployment Namespace: default CreationTimestamp: Tue, 05 Dec 2017 10:53:53 -0500 Labels: app=sunlife-analystrating-deployment Annotations: deployment.kubernetes.io/revision=1 Selector: app=sunlife-analystrating-deployment Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 1 max unavailable, 1 max surge Pod Template: Labels: app=sunlife-analystrating-deployment Containers: sunlife-analystrating-deployment: Image: registry.ng.bluemix.net/dockerservice/tensorflowrunningimage:02 Port: 5002/TCP Environment: <none> Mounts: <none> Volumes: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable OldReplicaSets: <none> NewReplicaSet: sunlife-analystrating-deployment-3230069030 (1/1 replicas created) Events: <none> 

以下是我的服务信息:

 kubectl describe service Name: kubernetes Namespace: default Labels: component=apiserver provider=kubernetes Annotations: <none> Selector: <none> Type: ClusterIP IP: 172.21.0.1 Port: https 443/TCP TargetPort: 32444/TCP Endpoints: 184.173.44.62:32444 Session Affinity: ClientIP Events: <none> Name: sunlife-analystrating-svc Namespace: default Labels: <none> Annotations: <none> Selector: app=sunlife-analystrating-deployment Type: NodePort IP: 172.21.210.178 Port: <unset> 5002/TCP TargetPort: 5002/TCP NodePort: <unset> 30484/TCP Endpoints: 172.30.111.147:5002 Session Affinity: None External Traffic Policy: Cluster Events: <none> 

以下是代码片断,我用它来公开容器内的其余客户端

 ------- def get(self): print("Hello World") response="Hello World" result_dict = { 'Analyst Rating': str(response) } return jsonify(result_dict) ------- if __name__ == '__main__': app.run(port='5002') ------- 

你不能得到任何GET请求,因为它似乎你使用POST方法

 *curl -I -X POST http://184.173.44.62:30484/analyst_rating -v 

另外,为什么你使用-I参数? 尝试执行:

 curl http://184.173.44.62:30484/analyst_rating -v 

如果这不起作用,您将不得不提供有关您的k8s服务规范的更多细节