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

2024-10-01 15:33:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从Kubernetes内部运行的容器使用pythonrestapi调用。 我可以使用吊舱内的服务

*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命令时,我得到以下错误:

^{pr2}$

我的集群IP是184.173.44.62,服务节点端口是30484。 我可以建立联系,但无法收到任何回应。 另外,我已经检查了舱内,我没有收到任何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>

下面是我用来在容器中公开rest客户机的代码片段

-------
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')
-------

Tags: nameipnoneapplocalhosthttphelloworld
1条回答
网友
1楼 · 发布于 2024-10-01 15:33:25

您无法获得任何get请求,因为似乎您使用了POST方法

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

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

^{pr2}$

如果这不起作用,您必须提供更多关于k8s服务规范的细节

相关问题 更多 >

    热门问题