Orisa
Orisa

Reputation: 19

GCP images and metadatas

I haven't found it on the Google documentation, but do custom GCP images also stores the metadatas from the referred instance?

I mean, if I deploy a new VM using a custom image, is it going to have the same metadatas than the original machine?

Upvotes: 0

Views: 670

Answers (1)

Priyashree Bhadra
Priyashree Bhadra

Reputation: 3597

Case 1 :

If you have stored your startup or shutdown script as a file hosted at an external location, such as Cloud Storage, and provided the startup script URL when creating an instance then your metadata is already present from the last instance.These files are downloaded onto the new VM instance and not in the metadata server which happens in usual VM creation process.

Case 2:

If you have created project wide metadata, then all the instances/resources will have the metadata from the project.

Set project-wide metadata to apply the metadata to all instances in the project. For example, if you define a project-wide metadata pair of baz=bat , that metadata pair is automatically applied to all instances in the project.

Case 3 :

If you haven't stored your startup or shutdown script as a file, then by default every instance stores its metadata on a metadata server and is different and independent. You can query this metadata server programmatically, from within the instance and from the Compute Engine API.

In your case as you mentioned, metadata will be different.

See for yourself,

  • Create a new VM with say name instance-1 and take a snapshot of the disk attached to the running VM instance
  • Make a custom image named image-1 from the snapshot.
  • Use this image-1 to make another instance named instance-2.

Now to check metadata values for the instances:

The metadata server uses directories to organize certain metadata keys. Any metadata entry ending in a trailing slash is a directory. For example, the disks/ entry is a directory of disks attached to that instance:

Detailed explanation of the commands:

curl "http://metadata.google.internal/computeMetadata/v1/instance/disks/" -H "Metadata-Flavor: Google"

0/

1/

2/

If you wanted more information about the disk 0/ directory, you can query the specific URL for that directory:

curl "http://metadata.google.internal/computeMetadata/v1/instance/disks/0/" -H "Metadata-Flavor: Google"

device-name

index

mode

type

So if you select device name for instances metadata-

It comes as instance-1 and instance-2 respectively for each of instances.

Upvotes: 4

Related Questions