OpenAPI 문서에서 Cloud Endpoints를 구성한 후에는 API 관리에 필요한 정보가 Cloud Endpoints에 포함되도록 이를 배포합니다.
Endpoints 구성을 배포하려면 gcloud
endpoints services deploy 명령어를 사용합니다. 이 명령어는 Endpoints와 기타 서비스에서 API 및 서비스를 생성하고 관리하기 위해 사용되는 Google의 기반 서비스 플랫폼인 서비스 인프라를 사용합니다. 이 페이지에서는 Endpoints에 OpenAPI 문서를 배포하는 방법을 설명합니다.
기본 프로젝트를 설정합니다. [YOUR-PROJECT-ID]를 GCP 프로젝트 ID로 바꿉니다.
gcloud config set project [YOUR-PROJECT-ID]
API 백엔드를 Kubernetes 또는 Kubernetes Engine에 배포하려면 다음 명령어를 실행하여 애플리케이션 기본 사용자 인증 정보로 사용할 새로운 사용자 인증 정보를 가져옵니다. 사용자 인증 정보는 kubectl를 승인하는 데 필요합니다.
gcloudauthapplication-defaultlogin
새 브라우저 탭이 열리고 계정을 선택하라는 메시지가 나타납니다.
openapi.json 구문 확인
OpenAPI 문서 파일은 YAML 형식 또는 JSON 형식일 수 있습니다. JSON 형식인 경우 파일을 배포하기 전에 구문을 확인하는 것이 좋습니다. openapi.json이 올바른 형식의 JSON 파일인지 확인하려면 vim과 같은 JSON 유효성 검사 텍스트 편집기에서 해당 파일을 열거나 온라인 JSON 린터 서비스 또는 Python을 사용합니다. 예를 들면 다음과 같습니다.
python-mjson.toolopenapi.json
읽기 쉽도록 JSON 파일을 예쁘게 인쇄합니다.
python-mjson.toolinput.json > output.json
input.json을 openapi.json 파일의 경로로 바꿉니다. output.json은 예쁘게 인쇄된 JSON 파일입니다.
OpenAPI 문서 유효성 검사
현재 모든 OpenAPI 구문이 Cloud Endpoints에서 지원되지는 않습니다. 배포하기 전에 OpenAPI 문서의 유효성을 검사할 수 있습니다.
OpenAPI 문서의 유효성을 검사하려면 다음 안내를 따르세요.
OpenAPI 문서가 있는 위치로 디렉터리를 변경합니다.
서비스를 만들 Google Cloud 프로젝트를 확인합니다.
커스텀 도메인 이름(예: myapi.example.com)을 사용하는 경우 잘못된 프로젝트에 서비스가 만들어지지 않도록 다음 명령어로 반환되는 프로젝트 ID의 유효성을 검사합니다.
gcloud config list project
기본 프로젝트를 변경해야 하는 경우 다음 명령어를 실행하고 [YOUR_PROJECT_ID]를 서비스를 만들 Google Cloud 프로젝트의 ID로 바꿉니다.
gcloudconfigsetproject[YOUR_PROJECT_ID]
다음 명령어를 실행하고 [YOUR_OPENAPI_DOCUMENT]를 API를 설명하는 OpenAPI 문서의 이름으로 바꿉니다.
그러면 gcloud 명령어는 Service Management API를 호출하여 OpenAPI 문서의 host 필드에 지정된 이름으로 관리형 서비스를 만듭니다. --validate-only 플래그를 지정해도 서비스가 만들어지지만 구성은 배포되지 않습니다. 서비스를 만들지 않고 OpenAPI 문서의 유효성을 검사할 수 있는 방법은 없습니다. 서비스를 삭제할 수 있지만 Service Management에서는 약 30일 동안 같은 이름의 서비스를 만들 수 없습니다.
OpenAPI 문서 배포
API를 배포할 준비가 되면 Service Management를 사용하여 API 구성을 업로드하고 관리형 서비스를 만들거나 업데이트하는 Google Cloud CLI를 실행합니다.
OpenAPI 문서를 배포하려면 다음 안내를 따르세요.
OpenAPI 문서가 있는 위치로 디렉터리를 변경합니다.
잘못된 프로젝트에 서비스가 만들어지지 않도록 다음 명령어로 반환되는 프로젝트 ID의 유효성을 검사합니다.
gcloud config list project
기본 프로젝트를 변경해야 하는 경우 다음 명령어를 실행하고 [YOUR_PROJECT_ID]를 서비스를 만들 Google Cloud 프로젝트의 ID로 바꿉니다.
gcloudconfigsetproject[YOUR_PROJECT_ID]
다음 명령어를 실행하고 [YOUR_OPENAPI_DOCUMENT]를 API를 설명하는 OpenAPI 문서의 이름으로 바꿉니다.
OpenAPI 문서에서 뭔가를 변경할 때마다 Endpoints가 가장 최신 버전의 API 서비스 구성을 보유하도록 OpenAPI 문서를 다시 배포해야 합니다. rollout 옵션을 managed로 설정하고 ESP를 배포한 경우 ESP를 다시 배포하거나 시작할 필요가 없습니다.
이 옵션은 배포된 최신 서비스 구성을 사용하도록 ESP를 구성합니다. 이 옵션을 지정하면 새 서비스 구성을 배포하고 최대 5분 후 ESP가 변경사항을 감지하고 자동으로 사용하기 시작합니다. ESP에 사용할 특정 구성 ID 대신 이 옵션을 지정하는 것이 좋습니다.
초기 Endpoints 구성 배포 후에는 사용자, 서비스 계정 또는 그룹에 Endpoints 구성을 다시 배포할 수 있도록 허용하는 역할을 부여할 수 있습니다. 자세한 내용은 API에 대한 액세스 권한 부여 및 취소를 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-21(UTC)"],[[["\u003cp\u003eCloud Endpoints uses the \u003ccode\u003egcloud endpoints services deploy\u003c/code\u003e command to deploy an OpenAPI document, which is essential for managing your API through Endpoints.\u003c/p\u003e\n"],["\u003cp\u003eBefore deploying, ensure you have a Google Cloud project, have configured Endpoints, and have verified your custom domain name if you are using one.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud\u003c/code\u003e command-line tool is used for the deployment process and requires preparation steps, including installation, updating, authorization, and setting the default project.\u003c/p\u003e\n"],["\u003cp\u003eYou can validate your OpenAPI document using the \u003ccode\u003e--validate-only\u003c/code\u003e flag in the deployment command, which creates a service but does not deploy the configuration.\u003c/p\u003e\n"],["\u003cp\u003eRedeploying your OpenAPI document after changes is crucial for Endpoints to use the latest configuration, and it is recommended to use the \u003ccode\u003erollout\u003c/code\u003e option set to \u003ccode\u003emanaged\u003c/code\u003e for automatic updates.\u003c/p\u003e\n"]]],[],null,["# Deploying the Endpoints configuration\n\nOpenAPI \\| [gRPC](/endpoints/docs/grpc/deploy-endpoints-config \"View this page for the Cloud Endpoints gRPC docs\")\n\n\u003cbr /\u003e\n\nAfter you configure Cloud Endpoints in an [OpenAPI\ndocument](/endpoints/docs/openapi/glossary#open_api_doc), you deploy it so that\nEndpoints has the information that it needs to manage your API.\nTo deploy the Endpoints configuration, you use the [`gcloud\nendpoints services deploy`](/sdk/gcloud/reference/endpoints/services/deploy)\ncommand. This command uses\n[Service Infrastructure](/service-infrastructure/docs/overview), Google's\nfoundational services platform, used by Endpoints and other\nservices to create and manage APIs and services. This page describes how to\ndeploy an OpenAPI document to Endpoints.\n\nPrerequisites\n-------------\n\nAs a starting point, this page assumes that you have:\n\n- Created a [Google Cloud\n project](/resource-manager/docs/creating-managing-projects) in which you have\n the **Editor** or **Owner** role. After the initial deployment, you can grant\n the more restrictive **Service Config Editor** role to a user, group, or\n service account. See [Granting and revoking access to the\n API](/endpoints/docs/openapi/control-api-access) for more information.\n\n- [Configured Endpoints](/endpoints/docs/openapi/configure-endpoints).\n\n- If you are using a custom domain name (such as `my-api.example.com`), you must\n [verify the domain name](/endpoints/docs/openapi/verify-domain-name) before\n you can deploy the OpenAPI document.\n\nPreparing the Google Cloud CLI for deployment\n---------------------------------------------\n\nYou use the `gcloud` command line tool to\ndeploy the configuration. See the [gcloud Reference](/sdk/gcloud/reference) for more information about the commands.\n\nTo prepare for the deployment:\n\n1. Install and initialize the [gcloud CLI](/sdk/docs/install).\n2. Update gcloud CLI: \n\n ```text\n gcloud components update\n ```\n3. Make sure that gcloud CLI is authorized to access your data and services: \n\n ```text\n gcloud auth login\n ```\n\n A new browser tab opens and you are prompted to choose an account.\n4. Set the default project. Replace `[YOUR-PROJECT-ID]` with your GCP project ID \n\n ```text\n gcloud config set project [YOUR-PROJECT-ID]\n ```\n5. If you will be deploying your API backend to either Kubernetes or Kubernetes Engine, run the following command to acquire new user credentials to use for Application Default Credentials. The user credentials are needed to authorize `kubectl`. \n\n ```bash\n gcloud auth application-default login\n ```\n A new browser tab opens and you are prompted to choose an account.\n\nValidating `openapi.json` syntax\n--------------------------------\n\nThe OpenAPI document file can be in YAML format or JSON format. If it is in JSON\nformat, we recommend that you verify the syntax before deploying the file. To\ncheck that your `openapi.json` is a well-formatted JSON file, you can open it in\na JSON-validating text editor such as `vim`, use an online JSON linter\nservice, or use Python, for example: \n\n python -m json.tool openapi.json\n\nTo improve readability, you can pretty-print the JSON file: \n\n python -m json.tool input.json \u003e output.json\n\nReplace `input.json` with the path to your `openapi.json` file. `output.json` is\nthe pretty-printed JSON file.\n\nValidating your OpenAPI document\n--------------------------------\n\nNot all OpenAPI constructs are [currently supported by\nCloud Endpoints](/endpoints/docs/openapi/openapi-limitations). Before\ndeploying, you can validate your OpenAPI document.\n\nTo validate your OpenAPI document:\n\n1. Change directory to the location containing your OpenAPI document.\n\n2. Confirm the Google Cloud project where you want to create the service.\n If you are using a custom domain name (such as, `myapi.example.com`),\n make sure to validate the project ID returned from the following command\n so that the service isn't created in the wrong project.\n\n gcloud config list project\n\n If you need to change the default project, run the following command\n and replace `[YOUR_PROJECT_ID]` with the Google Cloud project ID\n in which you want to create the service: \n\n gcloud config set project [YOUR_PROJECT_ID]\n\n3. Run the following command, and replace `[YOUR_OPENAPI_DOCUMENT]` with\n the name of the OpenAPI document that describes your API:\n\n gcloud endpoints services deploy [YOUR_OPENAPI_DOCUMENT] --validate-only\n\nThe `gcloud` command then calls the\n[Service Management](/service-infrastructure/docs/manage-config) API to\ncreate a managed service with the name that you specified in the `host` field\nin your OpenAPI document. When you specify the `--validate-only` flag, a service\nis still created, but the configuration isn't deployed. There isn't a way to\nvalidate your OpenAPI document without creating a service. Although you can\n[delete the service](/endpoints/docs/openapi/deleting-an-api-and-instances),\nService Management prevents you from creating a service with the same\nname for a period of approximately 30 days.\n\nDeploying the OpenAPI document\n------------------------------\n\nWhen you are ready to deploy your API, you run the Google Cloud CLI,\nwhich uses Service Management to upload your API configuration and\nto create (or update) a managed service.\n\nTo deploy your OpenAPI document:\n\n1. Change directory to the location containing your OpenAPI document.\n\n2. Validate the project ID returned from the following command to make sure that\n the service isn't created in the wrong project.\n\n gcloud config list project\n\n If you need to change the default project, run the following command\n and replace `[YOUR_PROJECT_ID]` with the Google Cloud project ID\n in which you want to create the service:: \n\n gcloud config set project [YOUR_PROJECT_ID]\n\n3. Run the following command, and replace `[YOUR_OPENAPI_DOCUMENT]` with\n the name of the OpenAPI document that describes your API:\n\n gcloud endpoints services deploy [YOUR_OPENAPI_DOCUMENT]\n\nThe first time that you run the previous command, Service Management\ncreates a new Endpoints service in the default project with a\nname that matches the text that you specified in the `host` field in your\nOpenAPI document and uploads your service configuration.\n\nAs it is creating and configuring the service, Service Management outputs\ninformation to the terminal. On successful completion, you see a line like the\nfollowing that displays the service configuration ID and the service name: \n\n```\nService Configuration [2017-02-13r0] uploaded for service [echo-api.endpoints.example-project-12345.cloud.goog]\n```\n\nIn the previous example, `2017-02-13r0` is the service configuration\nID and `echo-api.endpoints.example-project-12345.cloud.goog` is the service\nname.\n\nAfter a successful deployment,\nyou can view the API on the\n[**Endpoints** \\\u003e **Services**](https://console.cloud.google.com/endpoints)\npage in the Google Cloud console.\n\nIf you get an error message, see [Troubleshooting Endpoints\nconfiguration\ndeployment](/endpoints/docs/openapi/troubleshoot-config-deployment).\n\nRedeploying\n-----------\n\nWhenever you change something in your OpenAPI document, be sure to deploy it\nagain so that Endpoints has the most recent version of\nyour API's service configuration. You don't need to redeploy\nor restart ESP if you previously deployed ESP with\nthe\n[`rollout` option set to `managed`](/endpoints/docs/openapi/deploy-api-backend#deploying_your_api_and_esp).\nThis option\nconfigures ESP to use the latest deployed service configuration. When you\nspecify this option, up to 5 minutes after you deploy a new service\nconfiguration, ESP detects the change and automatically begins using it. We\nrecommend that you specify this option instead of a specific configuration ID\nfor ESP to use.\n\nAfter the initial Endpoints configuration deployment, you can\ngrant a user, service account, or group a role that allows them to redeploy the\nEndpoints configuration. See [Granting and revoking access to the\nAPI](/endpoints/docs/openapi/control-api-access) for more information.\n\nWhat's next\n-----------\n\n- [Deploying the API backend](/endpoints/docs/openapi/deploy-api-backend)\n- [Deploying on Kubernetes](/endpoints/docs/openapi/kubernetes-concept)\n- [Running ESP locally or on another platform](/endpoints/docs/openapi/running-esp-localdev)\n- [Getting the service name and configuration ID](/endpoints/docs/openapi/get-service-name-config-id)"]]