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
runpod.api_key = os.getenv("RUNPOD_API_KEY")
bot_name = 'Testing Pod Public IP 1'

pod = runpod.create_pod(
name=bot_name,
image_name="runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04",
gpu_count=1,
gpu_type_id='NVIDIA A40',
network_volume_id="8y",
volume_mount_path="/workspace",
ports= "8888/http,22/tcp,70001/tcp",
env={
"PUBLIC_KEY": "ssh-ed25519 ",
"JUPYTER_PASSWORD": "h7xw7gxh407nxshza6f3",
"RUNPOD_PUBLIC_IP": "10.2.25.69",
"RUNPOD_TCP_PORT_70001": 5000
},
support_public_ip=True,
docker_args="/workspace/start_finetune.sh",
container_disk_in_gb=20
)

print(pod)
runpod.api_key = os.getenv("RUNPOD_API_KEY")
bot_name = 'Testing Pod Public IP 1'

pod = runpod.create_pod(
name=bot_name,
image_name="runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04",
gpu_count=1,
gpu_type_id='NVIDIA A40',
network_volume_id="8y",
volume_mount_path="/workspace",
ports= "8888/http,22/tcp,70001/tcp",
env={
"PUBLIC_KEY": "ssh-ed25519 ",
"JUPYTER_PASSWORD": "h7xw7gxh407nxshza6f3",
"RUNPOD_PUBLIC_IP": "10.2.25.69",
"RUNPOD_TCP_PORT_70001": 5000
},
support_public_ip=True,
docker_args="/workspace/start_finetune.sh",
container_disk_in_gb=20
)

print(pod)
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?
No description
No description
21 Replies
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
How do I get these? What is the command in python? Port number more than 70000
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
When I create a pod I dont see it in the printed variable
{'id': 'dfg', 'desiredStatus': 'RUNNING', 'imageName': 'runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04', 'env': ['PUBLIC_KEY=ssh-ed25519 m', 'JUPYTER_PASSWORD=h7xw7gxh407nxshza6f3', 'RUNPOD_PUBLIC_IP=10.2.25.69', 'RUNPOD_TCP_PORT_70000=5000'], 'machineId': 'gp8l45q218uu', 'machine': {'podHostId': '85f0xhj08uxndo-644112f0'}}
{'id': 'dfg', 'desiredStatus': 'RUNNING', 'imageName': 'runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04', 'env': ['PUBLIC_KEY=ssh-ed25519 m', 'JUPYTER_PASSWORD=h7xw7gxh407nxshza6f3', 'RUNPOD_PUBLIC_IP=10.2.25.69', 'RUNPOD_TCP_PORT_70000=5000'], 'machineId': 'gp8l45q218uu', 'machine': {'podHostId': '85f0xhj08uxndo-644112f0'}}
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
Yeah But I passed that env variable myself. The actual assigned publib ip is something else
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo 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.
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
I created them like this
pod = runpod.create_pod(
name=bot_name,
image_name="runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04",
gpu_count=1,
gpu_type_id='NVIDIA A40',
network_volume_id="8y",
volume_mount_path="/workspace",
ports= "8888/http,22/tcp,70001/tcp",
env={
"PUBLIC_KEY": "ssh-ed25519 ",
"JUPYTER_PASSWORD": "h7xw7gxh407nxshza6f3",
"RUNPOD_PUBLIC_IP": "10.2.25.69",
"RUNPOD_TCP_PORT_70001": 5000
},
support_public_ip=True,
docker_args="/workspace/start_finetune.sh",
container_disk_in_gb=20
)
pod = runpod.create_pod(
name=bot_name,
image_name="runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04",
gpu_count=1,
gpu_type_id='NVIDIA A40',
network_volume_id="8y",
volume_mount_path="/workspace",
ports= "8888/http,22/tcp,70001/tcp",
env={
"PUBLIC_KEY": "ssh-ed25519 ",
"JUPYTER_PASSWORD": "h7xw7gxh407nxshza6f3",
"RUNPOD_PUBLIC_IP": "10.2.25.69",
"RUNPOD_TCP_PORT_70001": 5000
},
support_public_ip=True,
docker_args="/workspace/start_finetune.sh",
container_disk_in_gb=20
)
Okay
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
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
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Madiator2011 (Work)
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
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
Okay if I got this correct then, Then I create the pod like this
pod = runpod.create_pod(
name=bot_name,
image_name="runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04",
gpu_count=1,
gpu_type_id='NVIDIA A40',
network_volume_id="8y",
volume_mount_path="/workspace",
ports= "8888/http,22/tcp,70002/tcp",
env={
"PUBLIC_KEY": "ssh-ed25519 ",
"JUPYTER_PASSWORD": "h7xw7gxh407nxshza6f3",
},
support_public_ip=True,
docker_args="/workspace/start_finetune.sh",
container_disk_in_gb=20
)
pod = runpod.create_pod(
name=bot_name,
image_name="runpod/pytorch:2.2.0-py3.10-cuda12.1.1-devel-ubuntu22.04",
gpu_count=1,
gpu_type_id='NVIDIA A40',
network_volume_id="8y",
volume_mount_path="/workspace",
ports= "8888/http,22/tcp,70002/tcp",
env={
"PUBLIC_KEY": "ssh-ed25519 ",
"JUPYTER_PASSWORD": "h7xw7gxh407nxshza6f3",
},
support_public_ip=True,
docker_args="/workspace/start_finetune.sh",
container_disk_in_gb=20
)
Then I ssh into the pod and
printenv | grep -i RUNPOD_TCP_PORT_70002
printenv | grep -i RUNPOD_TCP_PORT_70002
This will give me the mapping But if I want to use the port and IP programatically, how can I do that?
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Asad Cognify
Asad CognifyOP17mo ago
But there is currently no way for me to get the port (even if symetrical) through the runpod python library?
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Madiator2011 (Work)
nope symetric ports are not even like full official and setting high port is kinda trick
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?