Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Shutdown Cloud Run Service at 11:59PM and start at 6AM via cron (Cloud Scheduler)

I have multiple cloud run services which are already created in Cloud Run. I have to shutdown cloud run service at night 11:59 PM and again start that service at morning 6 AM. 

Kindly guide me, so I can complete this task.

Thank You

0 1 251
1 REPLY 1

Hi @amolgawai,

Welcome to Google Cloud Community!

You can manage Cloud Run services' start and stop times, create Cloud Functions for these operations and use Cloud Scheduler to trigger them at set times. This automates your service management with Google Cloud.

  1. Create Cloud Functions
    • Go to Cloud Functions and click Create Function.
    • Stop Function: You can name it for example: stop-cloud-run, choose HTTP trigger, and add code to stop your Cloud Run service.
    • Start Function: Repeat, name it start-cloud-run, and add code to start your service.

  2. Set Up Cloud Scheduler Job
    • Go to Cloud Scheduler and click Create Job.
    • Stop Job: Name it stop-cloud-run, set time to 11:59 PM (59 23 * * *), and point it to the Stop Function URL.
    • Start Job: Name it start-cloud-run, set time to 6 AM (0 6 * * *), and point it to the Start Function URL.

  3. Test
    • Run the functions manually to ensure they work.
    • Check that the scheduler jobs trigger at the right times.

I hope this helps.

Top Labels in this Space