If you want to automatically stop your Pod when your workload is done, simply run the following command at the operating system level after your script is completed:
runpodctl stop pod $RUNPOD_POD_ID
runpodctl is our command line tool that is automatically installed in every Pod. RUNPOD_POD_ID is an environment variable that we pass to uniquely identify each Pod. Each runpodctl Pod instance is configured with an API key that is scoped to that Pod, so it cannot affect other Pods.
If you simply want to stop your Pod after a specific amount of time, you can run the following command:
nohup bash -c "sleep 2h; runpodctl stop pod $RUNPOD_POD_ID" &
sleep 2h; runpodctl stop pod $RUNPOD_POD_ID &
This simple command sleeps for 2 hours (change 2h to whatever you want), and then stops the Pod.
nohup ensures the process won't terminate if you close the web terminal window. Keep in mind that you will still incur disk fees on a stopped Pod.
If you want to terminate the Pod completely, you can configure your Pod with a zero-volume disk. In this case, stopping the Pod is equivalent to terminating it.
You can also request to terminate the Pod directly using a similar cli command:
runpodctl remove pod $RUNPOD_POD_ID
Updated 2 months ago