简体   繁体   中英

Google Compute Engine: increase memory/CPU of the instance

I would like to know if its possible to increase the CPU/memory of the instance on Google Compute Engine? I am currently running a small instance (g1-small) and I would like to move to n1-highmem-2.

Now it's possible: https://cloud.google.com/compute/docs/instances/changing-machine-type-of-stopped-instance

  1. Go to the VM Instances page .
  2. In the Name column, click the name of the instance that you want to change the machine type for.
  3. Click the Stop button to stop the instance, if you have not stopped it yet.
  4. After the instance stops (this may take couple minutes), click the Edit button at the top of the page.

This is not currently possible on Google Cloud Platform. For now, you can shut down your instance, and create a new instance with the persistent disk of the older instance attached as described in this StackOverflow answer .

Update- AS of the time of writing:

  • One way is to stop the instance, get to edit mode and configure machine to new configuration. Once done, you would need to start and it will come back up with latest config.
  • The easiest way is to go to VM instances section and you should be able to see "increase perf" in recommendation section of the VM listings. You can select from there itself with one click and it will be restarted with the selected config.

Call this Python function:

gcpChangeMachineType('project-id', 'us-west1-b', 'youInsanceName', 'custom-96-638976')

Put this in the same Python File:

def gcpChangeMachineType(project, zone, instance_name, newType):
    import googleapiclient.discovery
    compute = googleapiclient.discovery.build('compute', 'v1')
    instances = compute.instances()
    instances.stop(project=project, zone=zone, instance=instance_name).execute()
    instances.setMachineType(project=project, zone=zone, instance=instance_name, body={'machineType':'zones/{zone}/machineTypes/{newType}'.format(zone=zone, newType=newType)}).execute()
    instances.start(project=project ,zone=zone, instance=instance_name).execute()
    return(instances.get(project=project ,zone=zone, instance=instance_name).execute())

Other possibles machines:

 - f1-micro       # 1cpu 640MB
 - n1-standard-1
 - custom-1-6656
 - custom-2-13312
 - custom-4-26624
 - custom-10-66560
 - custom-12-79872
 - custom-96-638976

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM