22

On Google Compute Engine, is there a way to change the machine type (for example, add cpu cores) after the machine was created?

Tzach
  • 12,889
  • 11
  • 68
  • 115
  • 1
    Possible duplicate of [How to change machine type of GCE instance?](http://stackoverflow.com/questions/31312085/how-to-change-machine-type-of-gce-instance) – approxiblue Nov 12 '15 at 22:28

6 Answers6

17

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.

jvarela
  • 3,744
  • 1
  • 22
  • 43
Srini
  • 1,014
  • 8
  • 9
9

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.

aculich
  • 14,545
  • 9
  • 64
  • 71
Kristian
  • 91
  • 1
  • 1
7

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:

  1. Deleting the old instance (while making sure the disk is not deleted).
  2. Creating a new instance with the desired type and using the disk from the old instance (instead of creating a new one)
Tzach
  • 12,889
  • 11
  • 68
  • 115
  • 2
    Note that before deleting an instance it is good practice to write down all instance details to be able to re-create it with the same configuration as: - Zone - IP (fixed or ephemeral), note that ephemeral IP will change on new instance. - IP forwarding - Availability policies - Custom metadata - SSH keys - Scopes permissions You can retrieve instance information with command: gcloud compute instances describe INSTANCE --zone ZONE – Paolo P. Dec 11 '14 at 15:29
  • In addition to the ephemeral external IP, the internal IP will also change. – jgoldschrafe Dec 11 '14 at 21:19
  • 2
    Pity there wasn't a ways to just "edit machine type". In my limited knowledge, I can't see why its not possible to just attach a disk and run an image on a different machine. Anyone know why this would be so hard? Of course, assuming same architecture CPU etc. – Ashley Aitken May 02 '15 at 07:38
  • this is no longer true – josh123a123 Jul 13 '17 at 14:51
4

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
aculich
  • 14,545
  • 9
  • 64
  • 71
2

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.

0

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.

Kervin L
  • 474
  • 4
  • 5
  • Hi, welcome to Stackoverflow!! It would be great if you could [read these guidelines](https://stackoverflow.com/help/how-to-answer) before answering any question. Thanks. – Shanteshwar Inde May 14 '19 at 11:07