我正在尝试从Kubernetes内部运行的容器中使用Python Rest API调用。 我可以使用pod中的服务
*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。 我能够建立连接但无法接收任何响应。 另外,我在pod中检查过,我没有得到任何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')
-------
答案 0 :(得分:1)
您无法获得任何GET请求,因为您似乎使用了POST方法
long int sumOfGroup(int k) {
long int special = (k * k) + (k - 1);
long int limit = special - ((k-1) * 2);
cout << special << " " << limit << endl;
long int total = 0;
for(int i = special; i <= limit; i - 2){
total += i;
}
return total;
}
int main() {
int k;
cin >> k;
long answer = sumOfGroup(k);
cout << answer << endl;
return 0;
}
另外,为什么使用-I参数?尝试执行:
*curl -I -X POST http://184.173.44.62:30484/analyst_rating -v
如果这不起作用,您必须提供有关k8s服务规范的更多详细信息