How to get Public IP and set symmetrical port mapping on Pod via Python SDK
I have created a pod with python in the following way
I also tried to use the console for clarity, but even when I put 70001 in TCP it wont map 5000:5000 but instead it assigns a port itself.
Even when it does, how do I know which port it is via python?
23 Replies
Yes, sometimes you may get symetricall port mapping, but sometimes you don't
*even if you have added port number more than (? howmuch i forgot)
So to get the external port number you mapped you can get it from these env varibles inside the pod:
* TCP port 22:
RUNPOD_TCP_PORT_22
* Public ip: RUNPOD_PUBLIC_IP
How do I get these? What is the command in python?
Port number more than 70000
os.environ contains an list of environment variable i guess
so os.environ['RUNPOD_PUBLIC_IP']
like that, or if it doesn't work please search google 🙂
When I create a pod I dont see it in the printed variable
I still see your public ip
'RUNPOD_PUBLIC_IP=10.2.25.69',
if you don't have the port number there, its not exposed.
Yeah But I passed that env variable myself. The actual assigned publib ip is something else
keep in mind normal tcp port range:
No i think thats not the way you expose an tcp port
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.
ports= "8888/http,22/tcp,70001/tcp",
this is how you expose ports
please describe what are you having trouble with, what are you expecting, and what have you tried
I created them like this
Okay
"RUNPOD_TCP_PORT_70001": 5000 < this is unecessary btw
okay
I created a new pod
I want to know its public ip
I exposed port 5000 in ports parameter, but the mapping is asymetrical, how can I make it symetrical to 5000
Via python using runpod library
Im not sure how to get the public ip via runpod's library but you can access it inside the pod using env variables
I exposed port 5000 in ports parameter, but the mapping is asymetrical, how can I make it symetrical to 5000Thats random,there is a chance you can get it and may not get it all clear?
RUNPOD_TCP_PORT_70001 wont work like this
you will need to set port to something like 70001 +
then from inside pod you would need to reed env variable RUNPOD_TCP_PORT_70001 to see what symetric port got assigned for you
oh more than 70001
Okay if I got this correct then,
Then I create the pod like this
Then I ssh into the pod and
This will give me the mapping
But if I want to use the port and IP programatically, how can I do that?
as i said...
theres a chance you might not get it
But there is currently no way for me to get the port (even if symetrical) through the runpod python library?
Send this to somewhere else where you need it, via http if you are looking for a simple way
Via runpodctl exec if there is ( im not sure if this exists )
or you start a ssh connection, run commands there
nope symetric ports are not even like full official and setting high port is kinda trick
haha finally you got the role