Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Concerning instances created from instance-derived instance template

Hello everyone. Please I am relatively new to google cloud and still putting through its paces. I recently learnt how to create an instance template from a pre-existing vm instance. I want to know if the subsequent vm instances created from the template will have installed on them, software that was installed on the original instance that was used to create the instance template. For instance if I have jdk/jre installed on the original instance, will the subsequent instances have them installed? If not is there a way a way to achieve this effect? Thank you

Solved Solved
0 4 507
1 ACCEPTED SOLUTION

Howdy Imonike,

It is my understanding that you have likely created an instance template from a pre-existing VM.  This means that NEW VMs you create from the template will have the same machine specifications but will NOT be clones of the original VM's hard-disks which may have been customized with settings and applications.  Think about both you and I ordering a new home PC from Dell.  We may both purchase model "XYZ" and when we both receive the machines, they will be of the same specification.  This is like saying we both get new machines from the "template XYZ".  However, that is as far as it goes.  The original template will identify a "boot disk" that will be the basic disk from the manufacturer.     To create new Compute Engine machines that already contain changed configurations, you will want to create a custom boot image.  See the following for instructions:

https://cloud.google.com/compute/docs/images/create-custom

Once you have created a custom boot image, you can then create a template that references the custom image ... see:

https://cloud.google.com/compute/docs/instance-templates/create-instance-templates#based-on-existing...

When you do that, THEN when you create a new VM instance form your template, that will ALSO use the custom boot image as the base image from which the new machine will use.

However ... while I think I am directly answering your question ... let me make an alternative suggestion.  Instead of trying to create new Custom Images, consider walking into the world of Docker and creating a "Docker Image".  If you create a Docker image that can then be instantiated not only on vanilla GCP VMs but also in Kubernetes, on-premises and on other cloud providers.   Now, you may have solid reasons for going down the custom image path ... but I haven't heard it yet ... and would advise examining Docker images/containers to see if that won't be a better path.

View solution in original post

4 REPLIES 4

Howdy Imonike,

It is my understanding that you have likely created an instance template from a pre-existing VM.  This means that NEW VMs you create from the template will have the same machine specifications but will NOT be clones of the original VM's hard-disks which may have been customized with settings and applications.  Think about both you and I ordering a new home PC from Dell.  We may both purchase model "XYZ" and when we both receive the machines, they will be of the same specification.  This is like saying we both get new machines from the "template XYZ".  However, that is as far as it goes.  The original template will identify a "boot disk" that will be the basic disk from the manufacturer.     To create new Compute Engine machines that already contain changed configurations, you will want to create a custom boot image.  See the following for instructions:

https://cloud.google.com/compute/docs/images/create-custom

Once you have created a custom boot image, you can then create a template that references the custom image ... see:

https://cloud.google.com/compute/docs/instance-templates/create-instance-templates#based-on-existing...

When you do that, THEN when you create a new VM instance form your template, that will ALSO use the custom boot image as the base image from which the new machine will use.

However ... while I think I am directly answering your question ... let me make an alternative suggestion.  Instead of trying to create new Custom Images, consider walking into the world of Docker and creating a "Docker Image".  If you create a Docker image that can then be instantiated not only on vanilla GCP VMs but also in Kubernetes, on-premises and on other cloud providers.   Now, you may have solid reasons for going down the custom image path ... but I haven't heard it yet ... and would advise examining Docker images/containers to see if that won't be a better path.

Hello Kolban. Trust you are good.

I was able to create the custom image and the instance template from the image as described in the links you sent me, thanks for that. Now the thing is, when I try to log into instances created from the template using the cloudshell just check that indeed, the instances have Java installed or even just try to open the link of the specific instance's name in the cloud console, I get the error message that the instance was not found

This is the output from the cloudshell:

ERROR: (gcloud.compute.ssh) Could not fetch resource:
 - The resource 'projects/elite-impact-378112/zones/us-east1-b/instances/cicd-hkylvj' was not found

Perhaps I should explain how the instances are being created. They are being created from a Jenkins pipeline that I am trying to set up. I have a Jenkins instance running off my laptop. I have configured a Google Compute Engine cloud that uses my template for its machine configuration. The instances are created when I try to run a build. Any pointers would be deeply appreciated.

It seems I found the issue. My node retention time was too small. I have confirmed that the instances are created with Java installed but by Jenkins log throws errors about Java not being installed. I am still trying to debug that.

Thank you Kolban for your nuanced answer. I agree with you that going the docker/kubernetes route will be better. The thing is my docker skills are still rudimentary and I have not yet had the chance to learn kubernetes. Also I am trying to acquire devops skills and I started by trying to follow a tutorial about setting up a jenkins pipline that makes use of GCP vm instances to run builds. As I am new to both jenkins and GCP, I wanted to get a relatively simple pipeline running first, before trying something more complex like running the pipeline in a docker container(s) possibly being orchestrated by kubernetes. I will check out the links you sent and update as I make progress. Thank you.