GCP Gotcha : Limit Serverless scalability to avoir unlimited bills
I have been recently amazed by Google Cloud Run, on which I transferred a dockerized App that I was running on Digital Ocean for a fix 10 € / month bill. Now, as it is a very confidential-trial-and-test kind of app (for me to play with) it costs me nothing on GCP.
That’s could be the end of the story, but I recently saw that the scalable nature of Cloud Run means also a potentially scalable bill … Any attack on the url would mean a scale on the number of servers, and a scaled bill.
By default Cloud Run can scale up to 100 Servers :
So we need a way to limit this number to be on the safe side. For me I would like to limit to 2 instances, just because I want to play with GCP rather than going full speed in a production-crazy mode.
To do so, we first must find the list of the services that are “on” in our cloud run. GCP provide us in the console with the “services list” command :
We see here the services which are not used (marked with a cross) and the one in use (with a check). I use this information to set an environment variable with the service I want to update the scalability :
And then I update the service with the gcloud run services update command and the “--max-instances” parameter :
Then we can see that the autoscaling is limited, back in the console :
This way my bill is not going to sky-rocket unless I decide to scale-back again.