측정항목을 사용하여 애플리케이션 분석

이 빠른 시작에서는 Cloud Deploy를 사용하여 Google Cloud Observability의 측정항목을 기반으로 배포된 Cloud Run 서비스를 분석하여 애플리케이션이 예상대로 작동하는지 확인하는 방법을 보여줍니다.

이 빠른 시작에서 다루는 작업은 다음과 같습니다.

  1. Cloud Run 서비스 하나를 만들고 배포합니다.

    이 경우 Cloud Deploy를 사용하여 배포하지 않습니다.

  2. Google Cloud Observability에서 업타임 체크를 만듭니다.

    이 검사는 Cloud Run 서비스가 실행 중인지 모니터링합니다.

  3. Cloud Monitoring에서 알림 정책을 만듭니다.

    기본적으로 Cloud Deploy 분석은 Google Cloud Observability의 여러 유형의 측정항목을 사용할 수 있습니다. 이 정책은 업타임 체크에서 문제가 표시되면 알림을 만듭니다.

  4. Cloud Run 서비스를 식별하는 Skaffold 구성을 만듭니다.

  5. Cloud Deploy 배포 파이프라인 및 대상을 정의합니다.

    이 파이프라인에는 한 단계만 포함되며 대상 하나만 사용되고 분석 작업의 정의가 포함됩니다.

  6. 대상에 자동으로 배포되는 출시 버전을 만듭니다.

    애플리케이션이 배포된 후에는 분석이 출시의 작업으로 실행됩니다.

    서비스가 타겟에 성공적으로 배포되지만 알림 정책에서 알림을 생성하므로 출시가 실패해야 합니다.

  7. Cloud Run 서비스 정의를 변경하여 서비스의 인스턴스 수를 늘리고 새 버전을 만듭니다.

    이번에는 서비스가 성공적으로 배포되고 출시가 성공적으로 완료됩니다.

시작하기 전에

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Cloud Deploy, Cloud Build, Cloud Run, and Cloud Storage APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  6. Google Cloud CLI를 설치합니다.

  7. 외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

  8. gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.

    gcloud init
  9. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  10. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  11. Verify that billing is enabled for your Google Cloud project.

  12. Enable the Cloud Deploy, Cloud Build, Cloud Run, and Cloud Storage APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  13. Google Cloud CLI를 설치합니다.

  14. 외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

  15. gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.

    gcloud init

필요한 역할

Cloud Deploy 서비스 계정에 Cloud Deploy 작업을 실행하고 Cloud Run에 배포하는 데 필요한 권한이 있는지 확인하려면 관리자에게 프로젝트의 Cloud Deploy 서비스 계정에 다음 IAM 역할을 부여해 달라고 요청하세요.

역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

관리자는 커스텀 역할이나 다른 사전 정의된 역할을 통해 Cloud Deploy 서비스 계정에 필요한 권한을 부여할 수도 있습니다.

Cloud Deploy 서비스 계정에 대해 자세히 알아보기

Cloud Run 서비스 배포

이 빠른 시작에서는 Cloud Run이 이미 있어야 하는 알림 정책을 사용합니다. 따라서 여기서는 하나를 배포하고 나중에 동일한 서비스 이름을 사용하여 service.yaml를 정의합니다.

다음 명령어를 실행하여 초기 서비스를 만듭니다.

gcloud run deploy my-analysis-run-service \
  --image=us-docker.pkg.dev/cloudrun/container/hello@sha256:95ade4b17adcd07623b0a0c68359e344fe54e65d0cb01b989e24c39f2fcd296a \
  --project=PROJECT_ID \
  --region=us-central1 \
  --allow-unauthenticated

PROJECT_ID를 프로젝트 ID로 바꿉니다.

Google Cloud Observability 업타임 체크 만들기

이 업타임 체크는 실행 중인 서비스를 모니터링하여 서비스가 실행 중인지 확인합니다. 나중에 서비스에 실행 중인 사용 가능한 인스턴스가 하나 이상 없는 경우 알림을 생성하는 Google Cloud Observability 알림 정책을 만듭니다.

  1. 업타임 체크를 만들려면 다음 명령어를 실행합니다.

    gcloud monitoring uptime create my-analysis-run-service-cloud-run-uptime-check \
      --resource-type=cloud-run-revision \
      --resource-labels="project_id=PROJECT_ID,location=us-central1,service_name=my-analysis-run-service" \
      --project=PROJECT_ID \
      --protocol=https \
      --path="/" \
      --port=443 \
      --period=1 \
      --timeout=10 \
      --service-agent-auth="oidc-token" \
      --status-classes="2xx"
    
  2. 업타임 체크 ID를 복사합니다.

    방금 실행한 명령어의 출력에 ID가 포함되어 있습니다.

Skaffold 구성 및 서비스 정의 준비

이 빠른 시작에서는 샘플 Cloud Run 서비스를 배포하는 데 사용할 매니페스트를 식별하는 skaffold.yaml 파일을 만들고 Cloud Run 자체를 정의하는 service.yaml 파일도 정의합니다.

  1. 터미널 창을 엽니다.

  2. 새 디렉터리를 만들어 해당 디렉터리로 이동합니다.

mkdir deploy-analysis-run-quickstart
cd deploy-analysis-run-quickstart
  1. 다음 콘텐츠로 skaffold.yaml라는 파일을 만듭니다.
apiVersion: skaffold/v4beta7
kind: Config
manifests:
  rawYaml:
  - service.yaml
deploy:
  cloudrun: {}

이 구성 파일에 대한 자세한 내용은 skaffold.yaml 참조를 확인하세요.

  1. 다음 콘텐츠로 service.yaml이라는 파일을 만듭니다.
apiVersion: serving.knative.dev/v1
kind: Service
metadata: