Une fois votre API déployée, ses utilisateurs doivent pouvoir y accéder via un nom de domaine plutôt qu'une adresse IP. Vous pouvez utiliser l'une de ces deux méthodes :
Configurer .endpoints.PROJECT_ID.cloud.goog comme nom de domaine (où PROJECT_ID correspond à votre ID de projet Google Cloud).
Ou enregistrer votre propre nom de domaine (par exemple, example.com), ce qui implique de :
configurer les serveurs de noms DNS (ou utiliser Google Cloud DNS) ;
mettre à jour des adresses de registre ;
créer et maintenir des enregistrements DNS.
Si vous disposez déjà d'une infrastructure DNS ou si vous souhaitez enregistrer votre propre nom de domaine, consultez la page Publier une API à partir de votre nom de domaine pour plus d'informations.
Cette page explique comment configurer des API Cloud Endpoints pour utiliser .endpoints.PROJECT_ID.cloud.goog en tant que nom de domaine. Les étapes de configuration décrites sur cette page s'appliquent aux API qui utilisent gRPC sur Compute Engine, Google Kubernetes Engine ou Kubernetes.
Le domaine .cloud.goog est géré par Google et partagé par les clients Google Cloud. Étant donné que les projets Google Cloud ont un ID de projet unique, un nom de domaine au format .endpoints.PROJECT_ID.cloud.goog est unique et peut être utilisé comme nom de domaine pour votre API. Il n'est pas nécessaire de configurer le nom de domaine .endpoints.PROJECT_ID.cloud.goog. Si vous préférez, vous pouvez enregistrer votre propre nom de domaine.
Prérequis
Dans cette page, nous partons du principe que vous avez déjà créé votre API Cloud Endpoints et que vous l'avez déployée sur Compute Engine, Google Kubernetes Engine ou Kubernetes. Si vous avez besoin d'une API pour les tests, vous pouvez utiliser l'un des tutoriels pour vous guider dans la configuration et le déploiement d'un exemple d'API.
Configurer un DNS
La procédure suivante explique comment configurer un DNS pour les API Cloud Endpoints qui utilisent .endpoints.PROJECT_ID.cloud.goog comme nom du service Cloud Endpoints. Pour des raisons pratiques, cette procédure désigne le fichier de configuration de votre service gRPC par le nom service.yaml.
Pour configurer un DNS :
Ouvrez service.yaml et ajoutez le champ endpoints à ce fichier, comme indiqué dans l'extrait de code suivant :
En règle générale, les champs name et endpoints.name sont identiques.
Remplacez API_NAME par le nom de votre API (par exemple, bookstore ou my-cool-api).
Remplacez IP_ADDRESS par une adresse IPv4. L'adresse IP est une chaîne et doit être placée entre guillemets.
Par exemple, si vous déployez votre service d'API Endpoints sur une instance de machine virtuelle Compute Engine, vous pouvez utiliser l'adresse IP externe de cette machine virtuelle. Si vous exécutez votre code sur un groupe d'instances de machine virtuelle (ou de pods GKE) derrière un équilibreur de charge, vous pouvez également utiliser l'adresse IP de ce dernier.
Déployez votre fichier de configuration gRPC mis à jour sur Service Management à l'aide de la commande suivante :
Lorsque vous déployez le fichier service.yaml à l'aide de la commande gcloud ci-dessus, Service Management crée un enregistrement A DNS, my-cool-api.endpoints.my-project-id.cloud.goog, dont la résolution donne l'adresse IP cible 192.0.2.1. Vous devrez peut-être attendre quelques minutes pour que la nouvelle configuration DNS se propage.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/08 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/08 (UTC)."],[[["\u003cp\u003eUsers need a domain name to access a deployed API, rather than an IP address.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003e.endpoints.\u003c/code\u003e\u003cvar translate=no\u003ePROJECT_ID\u003c/var\u003e\u003ccode\u003e.cloud.goog\u003c/code\u003e as the domain name, which is managed by Google and unique to your Google Cloud project.\u003c/p\u003e\n"],["\u003cp\u003eConfiguring DNS involves updating your \u003ccode\u003eservice.yaml\u003c/code\u003e file with the \u003ccode\u003eendpoints\u003c/code\u003e field, including your API name and target IP address.\u003c/p\u003e\n"],["\u003cp\u003eDeploying the updated \u003ccode\u003eservice.yaml\u003c/code\u003e file to Service Management creates a DNS A-record that maps your API domain name to the specified IP address.\u003c/p\u003e\n"],["\u003cp\u003eAlternatively, users can register their own domain name and configure the relevant DNS infrastructure.\u003c/p\u003e\n"]]],[],null,["# Configuring DNS on the cloud.goog domain\n\n[OpenAPI](/endpoints/docs/openapi/cloud-goog-dns-configure \"View this page for the Cloud Endpoints OpenAPI docs\") \\| gRPC\n\n\u003cbr /\u003e\n\nAfter your API is deployed, users of your API need to access it through a domain name\nrather than an IP address. You can either:\n\n- Configure `.endpoints.`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.cloud.goog` as the domain name (where \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is your Google Cloud project ID).\n- Or register your own domain name, such as `example.com`, which entails:\n - Configuring DNS name servers (or using [Cloud DNS](/dns/docs)).\n - Updating registry addresses.\n - Creating and maintaining DNS records.\n\n If you already have a DNS infrastructure, or you want to register your own\n domain name, see [Serving an API from your domain name](/endpoints/docs/grpc/serving-apis-from-domains) for more information.\n\nThis page describes how to configure Cloud Endpoints APIs to use\n`.endpoints.`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.cloud.goog` as the domain\nname. The configuration steps on this page are applicable for APIs using\ngRPC running on Compute Engine, Google Kubernetes Engine, or Kubernetes.\n\nThe `.cloud.goog` domain is managed by Google and shared by Google Cloud\ncustomers. Because Google Cloud projects are guaranteed to have a globally unique project ID,\na domain name in the format `.endpoints.`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.cloud.goog` is unique and\ncan be used as the domain name for your API. Configuring the\n`.endpoints.`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.cloud.goog` domain name is optional. If you prefer, you\ncan register your own domain name.\n\nPrerequisites\n-------------\n\nAs a starting point, this page assumes that you have already created your\nCloud Endpoints API and deployed it to Compute Engine, Google Kubernetes Engine, or\nKubernetes. If you need an API for testing, you can use one of the\n[tutorials](/endpoints/docs/grpc/tutorials) that walk you through\nconfiguring and deploying a sample API.\n\nConfiguring DNS\n---------------\n\nThe following procedure describes how to configure DNS for\nEndpoints APIs that use\n`.endpoints.`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.cloud.goog` as the\nEndpoints service name. For convenience, the procedure refers to\nyour gRPC service configuration file as `service.yaml`.\n\nTo configure DNS:\n\n1. Open `service.yaml`, and add the `endpoints` field to the file as shown in the following code snippet: \n\n ```\n type: google.api.Service\n name: API_NAME.endpoints.PROJECT_ID.cloud.goog\n endpoints:\n - name: API_NAME.endpoints.PROJECT_ID.cloud.goog\n target: \"IP_ADDRESS\"\n \n ```\n\n Typically, the `name` field and the `endpoints.name`\n field are the same.\n2. Replace \u003cvar translate=\"no\"\u003eAPI_NAME\u003c/var\u003e with the name of your API (for example, `bookstore` or `my-cool-api`).\n3. Replace \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e with an IPv4 address. The IP address is a string and must be enclosed in quotation marks.\n\n For example, if you deploy your Endpoints API service to a\n Compute Engine virtual machine instance, you can use the external IP address\n of that virtual machine. Alternatively, if you run your code on a group of virtual\n machine instances (or GKE pods) behind a load balancer,\n you can use the IP address of the load balancer.\n4. Deploy your updated gRPC configuration file to Service Management by using the following command: \n\n ```\n gcloud endpoints services deploy service.yaml service.pb\n ```\n\nFor example, if the following is specified in the `service.yaml` file: \n\n```\ntype: google.api.Service\nname: my-cool-api.endpoints.my-project-id.cloud.goog\nendpoints:\n- name: my-cool-api.endpoints.my-project-id.cloud.goog\n target: \"192.0.2.1\"\n```\n\nWhen you deploy the `service.yaml` file by using the precediing `gcloud` command,\nService Management creates a DNS A-record,\n`my-cool-api.endpoints.my-project-id.cloud.goog`, which resolves to the target\nIP address, `192.0.2.1`. You might need to wait a few minutes for the new DNS\nconfiguration to propagate.\n\nWhat's next\n-----------\n\n- [Configuring Endpoints](/endpoints/docs/grpc/configure-endpoints)\n- [Enabling SSL for Endpoints](/endpoints/docs/grpc/enabling-ssl)\n- [Reserving a static external IP address](/compute/docs/configure-ip-addresses)\n- [Serving an API from your domain name](/endpoints/docs/grpc/serving-apis-from-domains)"]]