Reputation: 13376
On Google Compute Engine, is there a way to change the machine type (for example, add cpu cores) after the machine was created?
Upvotes: 23
Views: 15444
Reputation: 1034
It is now possible in the Google compute engine (You can refer to this document).
You just need to stop the instance. And you can then edit the instance type and restart.
Upvotes: 18
Reputation: 522
To change the machine type of your VM instance. You need first to stop your VM instance. After that, click edit then change the machine type and then save it.
Upvotes: 0
Reputation: 21
The Google Cloud documentation states that you can do this from the page that lists the VM Instances however it doesn't appear to be that way now. I found that you have to click on the image name in that list. That then brings up a page where you can Edit the instance including the type.
Upvotes: 2
Reputation: 13376
UPDATE: this answer is no longer true, as the ability to change instance type was added after this answer was written. See accepted answer.
Although there is no direct "edit machine type" option on GCE, the way to achieve that is:
Upvotes: 7
Reputation: 91
This seems to be possible in gcloud:
https://cloud.google.com/sdk/gcloud/reference/compute/instances/set-machine-type
gcloud compute instances set-machine-type
allows you to change the machine type of a virtual machine in the TERMINATED state (that is, a virtual machine instance that has been stopped). For example, if example-instance is a g1-small virtual machine currently in the TERMINATED state, running:
$ gcloud compute instances set-machine-type example-instance \
--zone us-central1-b --machine-type n1-standard-4
will change the machine type to n1-standard-4, so that when you next start example-instance, it will be provisioned as an n1-standard-4 instead of a g1-small.
Upvotes: 9
Reputation: 14855
Use gcloud compute instances set-machine-type
to change a stopped instance to a machine of another type, for example:
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
foobaz us-central1-a f1-micro 10.128.0.2 104.197.19.103 RUNNING
$ gcloud compute instances stop foobaz
$ gcloud compute instances set-machine-type foobaz --machine-type g1-small
$ gcloud compute instances start foobaz
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
foobaz us-central1-a g1-small 10.128.0.2 104.197.179.223 RUNNING
This assumes you've already set your default zone, e.g.:
$ gcloud config set compute/zone us-central1-a
Also, note the EXTERNAL_IP
has changed in the example above. If you want to the newly resized machine to keep the original IP address, then before you stop it you should promote the external IP address from ephemeral to static:
$ ipaddr=$(gcloud --format="value(networkInterfaces[0].accessConfigs[0].natIP)" compute instances describe foobaz)
$ gcloud compute addresses create foobaz-ip --addresses $ipaddr
Upvotes: 4