python - 来自kubernetes的“curl: (8) Weird server reply”

标签 python rest docker curl kubernetes

我正在尝试从Kubernetes内部运行的容器中使用Python Rest API调用。
我可以使用 pods 内的服务

*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。
我可以建立连接,但无法收到任何回复。
另外,我已经检查了 pods 内部,没有收到任何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服务规范的更多详细信息

关于python - 来自kubernetes的“curl: (8) Weird server reply”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47659088/

相关文章:

bash - 从另一个命令获取一些环境变量后,在远程主机上运行的 docker 容器中运行任意命令

docker - 什么是Docker跨平台架构

python - 尝试使用 str.contains 和 bool 掩码,但仅适用于 Pandas 中的单个值

php - Postman 生成的代码中的 postman-token header 属性是什么?

javascript - Angular $HTTP 响应语法错误 : Unexpected token E

java - 在 JAVA 中将 JSON 对象作为 POST 发送到 REST 服务

azure - 使用 Linux 操作系统将 Windows 容器(使用 Docker 构建)推送到 Azure 容器服务 (AWS)

python - 如何从循环中创建的组合框获取反馈

python - 使用 BeautifulSoup 或 golang colly 解析 HTML 时遇到问题

python - sqlalchemy - 对项目进行分组并遍历子列表