0

My question is similar to this one. I have a docker image, that contains a python file that accepts arguments from command line using sys.stdin(). I can run the image using the following command

cat file.csv | docker run -i -t my_image

It pipes the contents of file.csv to the image, and i get the output as expected.

Now i want to deploy this image to kubernetes. I can run the image on the server using docker without any problems. But as per this tutorial by google, if i curl to it, it should send a response back, but i am not getting it because i do not have a web server listening on any port. I went ahead and built a deployment using the following command.

kubectl run -i my_deployment --image=gcr.io/${PROJECT_ID}/my_image:v1 --port 8080

It built the deployment and i can see the pods running. Then i expose it.

kubectl expose deployment my_deployment --type=LoadBalancer --port 80 --target-port 8080

But if i try to access it using the IP assigned using curl,

curl http://allocated_ip

it just says connection refused.

How can deploy this docker image as a service and send contents of a file as an input to the service? Do i need a web server for that?

  • depends on how you want to get file contents – 4c74356b41 Jan 29 at 11:29
  • Through cat command. The python file uses sys.stdin() and it accepts a stream of data, which is what i want. – sid0972 Jan 29 at 12:13
  • how do you expect this to work? what is supposed to issue the cat command? where is the file located? – 4c74356b41 Jan 29 at 12:19
  • When the kubernetes service is created, i expect to send the contents of the file as input through curl or a python client. – sid0972 Jan 29 at 12:32
  • so you need something listening on the other end, sound logical, right? – 4c74356b41 Jan 29 at 12:34
1

Reading stdin and reading a web request are very different things.

If you want your input to come through HTTP you need an HTTP server that receives the request, parses it, and sends it to your application.

If you just want TCP, but not HTTP it's a little simpler,and you can probably do something with socat to listen on a socket and pass output to stdout and pipe that through your app.

But nothing in Kubernetes will magically convert TCP/IP to stdin for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.