대상에 애플리케이션 카나리아 배포

이 빠른 시작에서는 Cloud Deploy를 사용하여 카나리아 배포의 샘플 애플리케이션 이미지를 Google Kubernetes Engine 또는 Cloud Run에 제공하는 방법을 보여줍니다. GKE 연결된 클러스터에 카나리아 배포를 실행할 수도 있지만 GKE 및 Cloud Run만 이 빠른 시작에 표시됩니다.

카나리아 배포는 이미 배포된 애플리케이션 버전과 새 버전 간에 트래픽을 분할합니다. Cloud Run은 배포 파이프라인에서 구성한 비율을 기준으로 트래픽을 분배합니다. GKE가 새 버전을 일정한 비율의 포드에 배포합니다. 이 빠른 시작에서는 먼저 50%로 배포한 다음 100%로 배포합니다.

이 빠른 시작에서는 대상(prod)이 하나만 있습니다. 따라서 애플리케이션을 실행하기 위해 GKE 클러스터 또는 Cloud Run 서비스를 하나만 만듭니다.

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

  1. 하나의 GKE 클러스터를 만들거나 하나의 Cloud Run 서비스를 정의합니다.

    카나리아 배포를 GKE 연결된 클러스터에 배포할 수도 있지만 이 빠른 시작에서는 GKE 및 Cloud Run만 사용합니다.

  2. Skaffold 구성 및 Kubernetes 매니페스트를 만들어 배포할(사전 빌드된) 컨테이너 이미지를 지정합니다.

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

  4. 하나의 타겟에 자동으로 배포되는 출시 버전을 만들어 배포 파이프라인을 호출합니다.

    이 첫 번째 출시 버전은 카나리아 단계를 건너뜁니다.

  5. Google Cloud 콘솔에서 배포 파이프라인과 출시 버전을 확인합니다.

  6. 이번에는 카나리아 단계를 실행하여 애플리케이션을 50%로 배포하는 두 번째 출시 버전을 만듭니다.

  7. 100% 배포를 위해 출시 버전을 진행합니다.

시작하기 전에

  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. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Deploy, Cloud Build, GKE, Cloud Run, and Cloud Storage APIs.

    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

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

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

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

    gcloud init
  8. 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

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

  10. Enable the Cloud Deploy, Cloud Build, GKE, Cloud Run, and Cloud Storage APIs.

    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

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

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

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

    gcloud init
  14. CLI가 이미 설치되어 있으면 최신 버전으로 실행 중인지 확인합니다.

    gcloud components update
    

  15. 기본 Compute Engine 서비스 계정에 충분한 권한이 있는지 확인합니다.

    서비스 계정에 이미 필요한 권한이 있을 수 있습니다. 기본 서비스 계정의 자동 역할 부여를 중지한 프로젝트를 위해 포함된 단계입니다.

    1. 먼저 clouddeploy.jobRunner 역할을 추가합니다.

      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/clouddeploy.jobRunner"
      

    2. 특정 런타임의 개발자 역할을 추가합니다.
      • GKE 및 Gateway API를 사용하는 GKE의 경우:

        gcloud projects add-iam-policy-binding PROJECT_ID \
            --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
            --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
            --role="roles/container.developer"
        

      • Cloud Run의 경우:

        gcloud projects add-iam-policy-binding PROJECT_ID \
            --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
            --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
            --role="roles/run.developer"
        

    3. 런타임에 배포할 수 있는 actAs 권한이 포함된 iam.serviceAccountUser 역할을 추가합니다.

      gcloud iam service-accounts add-iam-policy-binding $(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/iam.serviceAccountUser" \
          --project=PROJECT_ID
      

런타임 환경 만들기

GKE

하나의 GKE Autopilot 클러스터를 만듭니다.

 gcloud container clusters create-auto canary-quickstart-cluster \
                  --project=PROJECT_ID \
                  --region=us-central1

GKE + Gateway API

  1. Istio 사용을 지원하는 권장 설정이 있는 하나의 GKE 클러스터를 만듭니다.

    gcloud container clusters create canary-quickstart-cluster \
           --machine-type=n1-standard-1 \
           --num-nodes 4 \
           --region=us-central1 \
           --project=PROJECT_ID
    
  2. 클러스터 사용자 인증 정보를 가져옵니다.

    gcloud