0

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)?

1

1 Answer 1

1

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.