"curl: (8) Weird server reply" from kubernetes

12/5/2017

I am trying to consume Python Rest API call from a container running inside the Kubernetes. I am able to consume the service inside the 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*

When I am running the curl command from outside the cluster, I am getting the below error:

    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

My Cluster IP is 184.173.44.62 and my service node port is 30484. I am able to make connections but not able to receive any response. Also, I have checked inside the pod, I am not getting any GET request.

Also, Following is my deployment info:

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>

and Following is my Service info:

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>

Following is the code snippet, that I have used to expose the rest client inside container

-------
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')
-------
-- Yadwinder Singh
curl
docker
kubernetes
python
rest

1 Answer

12/5/2017

You can't get any GET request because it seems that you use POST method

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

Also, why do you use -I parameter? Try to execute:

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

If this doesn't work, you'll have to provide more details about your k8s service specification

-- Ludek
Source: StackOverflow