Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcloud app deploy does not remove previous versions

I am running a Node.js app on Google App Engine, using the following command to deploy my code:

gcloud app deploy --stop-previous-version

My desired behavior is for all instances running previous versions to be terminated, but they always seem to stick around. Is there something I'm missing?

I realize they are not receiving traffic, but I am still paying for them and they cause some background telemetry noise. Is there a better way of running this command?

Example output of the gcloud app instances list: enter image description here As you can see I have two different versions running.

like image 492
Alon Avatar asked Apr 15 '17 19:04

Alon


People also ask

How do I get rid of gcloud app deploy?

Warning: You cannot undo this operation. If you want to delete a deployment, but keep all the underlying resources, you must use the Google Cloud CLI or the API. In the console, open the Deployments page.

How does gcloud app deploy work?

By default, the gcloud app deploy command deploys only the app. yaml file in your current directory. Whenever you run this command, App Engine generates a unique ID for the version that you deploy, deploys the version to the Cloud project you configured the gcloud CLI to use, and routes all traffic to the new version.

How do I uninstall App Engine versions?

You can find the list of your app versions in the Versions page. To delete the non-default versions, select the check boxes and then click Delete.

How long does gcloud app deploy take?

When firing of gcloud preview app deploy the whole process takes ~8 minutes, most of which is "updating service".


2 Answers

We accidentally blew through our free Google App Engine credit in less than 30 days because of an errant flexible instance that wasn't cleared by subsequent deployments. When we pinpointed it as the cause it had scaled up to four simultaneous instances that were basically idling away.

tl;dr: Use the --version flag when deploying to specify a version name. An existing instance with the same version will be replaced then next time you deploy.

That led me down the rabbit hole that is --stop-previous-version. Here's what I've found out so far:

--stop-previous-version doesn't seem to be supported anymore. It's mentioned under Flags on the gcloud app deploy reference page, but if you look at the top of the page where all the flags are listed, it's nowhere to be found.

I tried deploying with that flag set to see what would happen but it seemingly had no effect. A new version was still created, and I still had to go in and manually delete the old instance.

There's an open Github issue on the gcloud-maven-plugin repo that specifically calls this out as an issue with that plugin but the issue has been seemingly ignored.

At this point our best bet at this point is to add --version=staging or whatever to gcloud deploy app. The reference docs for that flag seem to indicate that that it'll replace an existing instance that shares that "version":

--version=VERSION, -v VERSION

The version of the app that will be created or replaced by this deployment. If you do not specify a version, one will be generated for you.

(emphasis mine)

Additionally, Google's own reference documentation on app.yaml (the link's for the Python docs but it's still relevant) specifically calls out the --version flag as the "preferred" way to specify a version when deploying:

The recommended approach is to remove the version element from your app.yaml file and instead, use a command-line flag to specify your version ID

like image 196
IAmKale Avatar answered Sep 17 '22 06:09

IAmKale


As far as I can tell, for Standard Environment with automatic scaling at least, it is normal for old versions to remain "serving", though they should hopefully have zero instances (even if your scaling configuration specifies a nonzero minimum). At least that's what I've seen. I think (I hope) that those old "serving" instances won't result in any charges, since billing is per instance.

I know most of the above answers are for Flexible Environment, but I thought I'd include this here for people who are wondering.

(And it would be great if someone from Google could confirm.)

like image 37
aldel Avatar answered Sep 20 '22 06:09

aldel