7

Is it possible? Official manual consists this:

Deterministic instance templates

But no more info how can I do this. Maybe someone have already did that? Tnx in advance.

d.ansimov
  • 2,131
  • 2
  • 31
  • 54
  • 1
    I was able to create an image from my disk and than use that image to create a template. I followed the steps for images creation mentioned on this link(https://cloud.google.com/compute/docs/images#create_an_image_from_a_root_persistent_disk). I think using snapshot of the disk is currently not possible to create the instance templates. – Faizan Jan 21 '15 at 19:23
  • tnx, m8, it seems you're right.... my workaround was to create template with `metadata startup-script-url=gs://my-bucket/startup-script.sh`, but it runs in every time i reboot an instance till i manually delete metadata from instance attributes via GCE web interface, which is no good.. I'll try your way, but maybe you can tell me, how to make startup script run only once with instance creation?.. Tnx in advance. – d.ansimov Jan 22 '15 at 13:29
  • and post your answer, please, i'll mark it solved. – d.ansimov Jan 22 '15 at 13:39

3 Answers3

7

It's possible. Here's the process:

  1. Create your Snapshot
  2. Create Disk from your Snapshot
  3. Create an Image from Disk
  4. Create an Instance Template from Image
Cigogne Eveillée
  • 2,178
  • 22
  • 36
6

So my solution is following:

  1. I created an instance.
  2. Install the required services on that instance.
  3. Created the image from the disk using the steps mentioned on this link.
  4. With that Image created a new template.

The startup scripts will run on instance boots up or restarts. So the only way I found to run it once is the same which you have tired i.e deleting them from metadata. In my setup when using startup scripts I don't reboot the instances I rather delete them and create a new ones if required.

Faizan
  • 1,937
  • 13
  • 18
-1

I don't know whether it is anew feature, but you can simply replicate an instance by

  1. Creating a snapshot
  2. When the snapshot is ready, click on it (it'll show the details)
  3. In the breadcrumbs bar, click on Create Instance.

It'll take a minute or so and the new instance will start-up, and that's all!

Nepaluz
  • 669
  • 1
  • 12
  • 27