Python code that works locally does not work on Kubernetes clusters

1/10/2020

I am working on a web server with a Python flask and passing data to the post method.

Let's say your Python flask web server is A, and B is a python file that sends data to server A as a post.

I planned to create a pod through deployment of A and pod as a job.

When testing on a local computer, it ran without problems and replaced only the ip address with the Kubernetes service name (to use the dns service).

But the problem is A 500 error.

I don't know what's wrong ... Please help me.

class Influx_Request3(Resource):
    def post(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument('carlist', type=str)
            parser.add_argument('cardataframe', type=str)
            parser.add_argument('cardict', type=str)
            args = parser.parse_args()

            print(args.carlist)
            print("args")

            _carlist = args['carlist']
            _cardataframe = args['cardataframe']
            _cardict = args['cardict']

            print(_carlist)
            print("_carlist")

            Analysis_Extraction_post(2019, 10, 14, 1, _carlist, _cardataframe, _cardict)
        except Exception as e:
            return {'error':str(e)}

This is the part that receives data from A web server.

Try printing '_carlist' and 'args' with print will not print.

If you try kubectl logs pod(A)

10.244.1.46--[10 / Jan / 2020 08:17:50]" POST / extraction3 HTTP / 1.1 "500-

Only output like this

NAME                                        READY   STATUS      RESTARTS   AGE
pod/analysis-extraction-6477dcc645-vcfdw    1/1     Running     0          10m
pod/analysis-influxinput-588d458f87-j48ls   1/1     Running     0          3h2m
pod/analysis-mongo-7p6sd                    0/1     Completed   0          10m
pod/busybox                                 1/1     Running     27         27h
pod/influx-695b89d797-h2fck                 1/1     Running     0          3h
pod/webserver-589dd46884-mzq5d              1/1     Running     0          3h

NAME                       TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/extraction-svc     ClusterIP   10.96.40.221    <none>        3000/TCP   3h1m
service/influxinput-svc    ClusterIP   10.96.153.210   <none>        5000/TCP   3h2m
service/influxservice      ClusterIP   10.96.212.119   <none>        8086/TCP   3h
service/kubernetes         ClusterIP   10.96.0.1       <none>        443/TCP    3h3m
service/webserverservice   ClusterIP   10.96.33.170    <none>        3000/TCP   3h

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/analysis-extraction    1/1     1            1           10m
deployment.apps/analysis-influxinput   1/1     1            1           3h2m
deployment.apps/influx                 1/1     1            1           3h
deployment.apps/webserver              1/1     1            1           3h

NAME                                              DESIRED   CURRENT   READY   AGE
replicaset.apps/analysis-extraction-6477dcc645    1         1         1       10m
replicaset.apps/analysis-influxinput-588d458f87   1         1         1       3h2m
replicaset.apps/influx-695b89d797                 1         1         1       3h
replicaset.apps/webserver-589dd46884              1         1         1       3h

NAME                       COMPLETIONS   DURATION   AGE
job.batch/analysis-mongo   1/1           2m24s      10m

The code you are requesting.

    carlist = json.dumps(carList, cls=NumpyEncoder)
    cardataframe = df_service.to_json()
    cardict = json.dumps(col_dict)

    data = {'carlist':carlist, 'cardataframe':cardataframe, 'cardict':cardict}
    res = requests.post('http://extraction-svc:3000/extraction3', data=data)
    print("request success")

https://www.programcreek.com/python/example/104294/flask_restful.reqparse.RequestParser

This is the site I referenced.

See the third example.

Try again and return a response code of 200. But still no output.

10.244.1.53 - - [13/Jan/2020 02:31:46] "POST /extraction3 HTTP/1.1" 200 -

kubectl describe service extraction-svc

Name:              extraction-svc
Namespace:         default
Labels:            <none>
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"extraction-svc","namespace":"default"},"spec":{"ports":[{"port":3...
Selector:          app=analysis-extraction
Type:              ClusterIP
IP:                10.96.8.131
Port:              <unset>  3000/TCP
TargetPort:        3000/TCP
Endpoints:         10.244.1.63:3000
Session Affinity:  None
Events:            <none>
-- 윤태일
flask
kubernetes
python

1 Answer

1/14/2020

Putting flush in the print output in the python code worked surprisingly. I don't know what the principle is.

print ("", flush = True)
-- 윤태일
Source: StackOverflow