Score:0

How to get GCE instance labels using metadata service?

in flag

In the GCP console I can set labels (key=value) to instances.

How to I access that information through the metadata service (preferably using curl)?

vn flag
Get the instance ID out of metadata, then access https://cloud.google.com/compute/docs/reference/rest/v1/instances/get.
Score:1
id flag
Leo

You can Query default vm metadata and custom metadata such as startup and shutdown scripts with curl like is showed in the following example :

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

Also, as you mention, you can use guest attributes or custom metadata for situations where you must publish infrequent and low volume data as explained in this link. You can also query the metadata server to get these values as is shown below:

curl http://metadata.google.internal/computeMetadata/v1/instance/guest-attributes/**NAMESPACE**/**KEY**  -H "Metadata-Flavor: Google"

Replace:

NAMESPACE: the namespace for the guest-attributes key that you want to query.

KEY: the path within guest-attributes from which you want to read the metadata value.

Alternatively, you can return all the guest attribute values in one request. Replace NAMESPACE with the namespace for the guest-attributes key that you want to query.

curl http://metadata.google.internal/computeMetadata/v1/instance/guest-attributes/NAMESPACE/ -H "Metadata-Flavor: Google"
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.