R
RunPod4mo ago
Shaplow

How to send request to a pod ?

Hello, for various reasons, I have a docker image that I want to run on a pod with a flask api. Except that I can't send any request, locally everything works but as soon as I put it on a pod it's problematic. First of all, I can't get a public IP address, so I thought I'd go through https://{pod_id}-{internal_port}.proxy.runpod.net/ping, but still, my requests don't work. So I tried using nginx to redirect requests to my container's internal port, but again, I'm having a bit of trouble with nginx, it doesn't seem to work. Is there something I've misunderstood about how to use runpod?
10 Replies
Shaplow
ShaplowOP4mo ago
def start_runpod_pod(): pod_template = { "cloudType": "CLOUD", "gpuType": "NVIDIA L4", "region": "EU_WEST_1", "numGpus": 1, "container": { "image": "my_image", "ports": "5000/http" }, "volumeInGb": 10, "containerDiskInGb": 10 }
pod = runpod.create_pod("facefusion_pod", pod_template["container"]["image"], pod_template["gpuType"]) return pod['id'] I use this for create a pod if ever
justin
justin4mo ago
https://discord.com/channels/912829806415085598/1207214335605088266/1207229710304550924 Make sure to host ur flask application on port 0.0.0.0 It works fine
Shaplow
ShaplowOP4mo ago
@justin [Not Staff] Thanks for answering ! Assuming I'm a real noob, I don't understand everything, do I have to use nginx? And can I use HTTP://{pod_id}-{internal_port}.proxy.runpod.net/ping for example to test my flask ping route? My dockerfile have this : EXPOSE 5000 CMD gunicorn -b 0.0.0.0:5000 routes:app --timeout 0 So i already bind 0.0.0.0 root@88b9feb930bd:/workspace# curl -k https://k8lq4mukjm8ibq-5000.proxy.runpod.net/ping root@88b9feb930bd:/workspace# curl -k http://k8lq4mukjm8ibq-5000.proxy.runpod.net/ping <html> <head><title>301 Moved Permanently</title></head> <body> <center><h1>301 Moved Permanently</h1></center> <hr><center>cloudflare</center> </body> </html> root@88b9feb930bd:/workspace# curl -k http://0.0.0.0:5000/ping {"status":"OK"}
justin
justin4mo ago
no need for nginx. use a standard runpod template first, install flask. ask chatgpt for a basic flask app to bind to port 0.0.0.0 can read the thread i sent as it pretty similar question
Shaplow
ShaplowOP4mo ago
i read all i don't get it sorry i talk with gpt for 3 hours, nothing i don't get the proxy thing why can't just have an ip ?
justin
justin4mo ago
Did u try to launch flask and bind it to 0.0.0.0? i guess let's start there and u use the proxy so u can ping the server? u can expose over public ip if it supports it
justin
justin4mo ago
Expose ports | RunPod Documentation
Exposing ports on your pod to the outside world: Learn how to expose ports via RunPod's Proxy or TCP Public IP, and discover the benefits and limitations of each method, including symmetrical port mapping requests and proxy timeout considerations.
justin
justin4mo ago
basically proxy is for http requests (what u wanna do) if u wanna do more, can do the public ip method also not too sure about dockerfile port exposing, i tend to do it through the console. so maybe this is where we are diverging maybe someone else can help on the exposing ports programatically, i saw ur thing here Okay step by step manually at least: I create a runpod template on: runpod/pytorch:2.1.0-py3.10-cuda11.8.0-devel-ubuntu22.04 Create a virtualEnv: python3 -m venv venv source venv/bin/activate pip install flask Run the flask app: python main.py
from flask import Flask

app = Flask(__name__)

@app.route('/hello', methods=['GET'])
def hello_world():
return {"text": "hello"}

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
from flask import Flask

app = Flask(__name__)

@app.route('/hello', methods=['GET'])
def hello_world():
return {"text": "hello"}

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
**make sure that the runpod by edit template, has the port exposed on port 5000
justin
justin4mo ago
No description
justin
justin4mo ago
No description
Want results from more Discord servers?
Add your server