Istio 1.11 이상에서 Anthos Service Mesh로 마이그레이션

이 튜토리얼에서는 Istio를 사용하는 Google Kubernetes Engine(GKE) 클러스터에서 Google의 완전 관리형 Istio 호환 서비스 메시인 관리형 Anthos Service Mesh를 사용하는 새 클러스터로 애플리케이션을 마이그레이션하는 방법을 보여줍니다.

이 튜토리얼의 목표는 다음과 같습니다.

  1. 새 Google Kubernetes Engine 클러스터를 만들고 클러스터에 Istio 및 Istio 인그레스 게이트웨이를 설치합니다. 이 클러스터는 마이그레이션하려는 기존 클러스터 역할을 합니다.
  2. Istio를 사용하는 클러스터에 Online Boutique 샘플 애플리케이션을 배포합니다.
  3. 동일한 Google Cloud 프로젝트에 다른 Google Kubernetes Engine 클러스터를 만듭니다.
  4. 두 번째 클러스터에서 관리형 Anthos Service Mesh를 사용 설정하고 Anthos Service Mesh 인그레스 게이트웨이를 배포합니다.
  5. Anthos Service Mesh를 사용하는 클러스터에 Online Boutique를 배포하여 Istio를 사용하는 클러스터에서 배포를 복제합니다.
  6. Istio를 사용하는 클러스터에서 Istio의 트래픽 분할 기능을 사용하여 Istio를 사용하는 클러스터에서 사용자 트래픽의 50%를 Anthos Service Mesh를 사용하는 클러스터로 이전합니다.
  7. Istio를 사용하는 클러스터의 도메인 이름 시스템(DNS) 항목이 Anthos Service Mesh를 사용하는 클러스터를 가리키도록 하여 Istio에서 Anthos Service Mesh로의 마이그레이션을 완료합니다.

사용자 트래픽이 Istio를 사용하는 클러스터와 Anthos Service Mesh를 사용하는 클러스터 간에 50-50으로 분할됩니다. 각 클러스터에 자체 Online Boutique 배포가 있습니다.

카나리아 배포

'카나리아 배포'는 새 버전을 모든 사용자에게 출시하기 전에 일부 소프트웨어의 새 버전을 테스트하기 위해 소프트웨어 개발에 사용되는 기술입니다. 이 배포에서는 새 버전으로 전송되는 트래픽의 비율이 점진적으로 증가합니다. 이 튜토리얼에서는 관리형 Anthos Service Mesh를 사용하는 새 클러스터를 설정하고 사용자 트래픽을 해당 클러스터로 점진적으로 전환합니다. 먼저 새 클러스터로 사용자 트래픽 중 0%를, 그런 다음 50%를, 마지막으로 100%를 전달합니다. 프로덕션에서는 더 작은 단위로 세분화하여 늘려야 합니다. 새 클러스터가 트래픽의 일정 비율을 처리할 수 없음을 알게 되면 언제든지 0%로 줄여 롤백할 수 있습니다.

카나리아 제어 영역과 카나리아 클러스터 비교

Istio에서 관리형 Anthos Service Mesh로 마이그레이션하기 위해 일반적으로 사용하는 전략에는 두 가지가 있습니다.

  • 카나리아 제어 영역 마이그레이션: 이 전략에서는 현재 Istio가 설치된 동일한 클러스터에 관리형 Anthos Service Mesh를 프로비저닝합니다.
  • 카나리아 클러스터 마이그레이션: 이 전략에서는 새 클러스터를 만든 후 이 클러스터에 관리형 Anthos Service Mesh를 프로비저닝합니다.

이 튜토리얼에서는 카나리아 클러스터 마이그레이션 전략을 설명합니다.

비용

이 튜토리얼에서는 비용이 청구될 수 있는 다음과 같은 Google Cloud 구성요소를 사용합니다.

이 튜토리얼을 마치면 만든 리소스를 삭제하여 비용이 계속 청구되지 않도록 할 수 있습니다. 자세한 내용은 삭제를 참조하세요.

시작하기 전에

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. Google Cloud Console의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 선택하거나 만듭니다.

    프로젝트 선택기로 이동

  3. Google Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다.

  4. 필요한 API를 사용 설정합니다.

    API 사용 설정

  5. Google Cloud Console의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 선택하거나 만듭니다.

    프로젝트 선택기로 이동

  6. Google Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다.

  7. 필요한 API를 사용 설정합니다.

    API 사용 설정

Cloud Shell 실행

이 튜토리얼에서는 Google Cloud에서 호스팅되는 셸 환경인 Cloud Shell을 사용하여 Google Cloud 리소스를 관리할 수 있습니다.

Cloud Shell에는 Google Cloud CLI, kubectl, istioctl 명령줄 도구가 사전 설치되어 있습니다. gcloud CLI에서는 Google Cloud의 기본 CLI를 제공합니다.

이 페이지의 오른쪽 상단에서 Cloud Shell 세션을 열고 을 클릭한 다음 확인을 클릭합니다. 페이지 하단의 프레임에서 Cloud Shell 세션이 열립니다. 해당 Cloud Shell 세션에서 다음 명령어를 완료합니다.

샘플 코드 다운로드

사용할 Kubernetes 및 Istio 리소스가 포함된 git 저장소를 클론합니다.

  git clone https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git
  git clone https://github.com/GoogleCloudPlatform/microservices-demo.git

Istio를 사용하는 클러스터 설정

클러스터 만들기 및 Istio 설치

이 섹션에서는 Istio를 사용하는 클러스터를 만듭니다. 실제로는 이미 사용 중인 클러스터입니다.

  1. PROJECT_ID프로젝트 ID로 바꾸고 새 클러스터를 만듭니다.

    gcloud container clusters create cluster-with-istio \
      --project=PROJECT_ID \
      --zone=us-central1-a \
      --machine-type=e2-standard-2 --num-nodes=3
    
  2. 클러스터를 더욱 간편하게 사용할 수 있도록 클러스터 컨텍스트 이름을 바꿉니다.

    kubectl config rename-context \
      gke_PROJECT_ID_us-central1-a_cluster-with-istio \
      cluster-with-istio
    
  3. 클러스터 컨텍스트 이름이 변경되었는지 확인합니다.

    kubectl config get-contexts --output="name"
    
  4. 클러스터에 Istio를 설치합니다. 편의상 Istio의 기본 프로필istioctl 설치와 일치하는 버전을 설치합니다.

    istioctl install
    

    'y'를 입력한 후 Enter 키를 누르라는 메시지가 표시됩니다.

    출력은 다음과 비슷합니다.

    This will install the Istio X.Y.Z default profile with ["Istio core" "Istiod" "Ingress gateways"] components into the cluster. Proceed? (y/N)
    ✔ Istio core installed
    ✔ Istiod installed
    ✔ Ingress gateways installed
    ✔ Installation complete
    Making this installation the default for injection and validation.
    

Online Boutique 배포

  1. Online Boutique를 onlineboutique라는 별도의 네임스페이스에 배포합니다. 네임스페이스를 만드세요.

    kubectl \
      --context cluster-with-istio \
      create namespace onlineboutique
    
  2. 사용자 트래픽을 모방하는 부하 생성기를 포함한 Online Boutique의 12개 서비스를 배포합니다.

    kubectl \
      --namespace=onlineboutique \
      --context=cluster-with-istio \
      apply -f microservices-demo/release/kubernetes-manifests.yaml
    
  3. 이전 단계에서는 공개 IP 주소가 할당되는 frontend-external 유형의 서비스(LoadBalancer 유형)도 배포했습니다. 하지만 Istio 인그레스 게이트웨이 배포를 통해서만 공개 인그레스를 허용할 수 있습니다. frontend-external 서비스 리소스를 삭제하세요.

    kubectl \
      --namespace=onlineboutique \
      --context=cluster-with-istio \
      delete service frontend-external
    
  4. 공개 트래픽이 Online Boutique에 액세스할 수 있도록 Istio Gateway 리소스 및 Istio VirtualService 리소스를 배포합니다.

    kubectl \
      --namespace=onlineboutique \
      --context=cluster-with-istio \
      apply -f microservices-demo/istio-manifests/frontend-gateway.yaml
    
  5. Istio 인그레스 게이트웨이의 공개 IP 주소를 가져옵니다.

    kubectl \
      --namespace istio-system \
      --context=cluster-with-istio \
      get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'
    
  6. istio-ingressgateway 서비스의 공개 IP 주소를 복사한 후 웹브라우저를 통해 액세스합니다. Online Boutique 샘플 앱이 표시됩니다.

관리형 Anthos Service Mesh를 사용하는 새 클러스터 설정

클러스터 만들기 및 관리형 Anthos Service Mesh 프로비저닝

이 섹션에서는 마이그레이션할 클러스터를 만듭니다. Istio를 사용하는 클러스터에서 배포를 복제하기 위해 관리형 Anthos Service Mesh를 프로비저닝하고 Online Boutique를 배포합니다.

  1. 프로젝트 번호를 환경 변수에 저장합니다.

    export PROJECT_NUMBER=$(gcloud projects \
      describe PROJECT_ID --format='get(projectNumber)')
    
  2. 새 클러스터를 만듭니다.

    gcloud container clusters create cluster-with-managed-asm \
      --project=PROJECT_ID --zone=us-central1-a \
      --machine-type=e2-standard-4 --num-nodes=2 \
      --workload-pool PROJECT_ID.svc.id.goog \
      --labels mesh_id=proj-${PROJECT_NUMBER}
    
  3. 클러스터를 더욱 간편하게 사용할 수 있도록 클러스터 컨텍스트 이름을 바꿉니다.

    kubectl config rename-context \
      gke_PROJECT_ID_us-central1-a_cluster-with-managed-asm \
      cluster-with-managed-asm
    
  4. 클러스터 컨텍스트 이름이 변경되었는지 확인합니다.

    kubectl config get-contexts --output="name"
    
  5. 프로젝트의 Fleet에 Anthos Service Mesh를 사용 설정합니다. Fleet은 함께 관리할 수 있는 Kubernetes 클러스터 및 기타 리소스의 논리적 그룹입니다.

    gcloud container fleet mesh enable --project PROJECT_ID
    

    출력은 다음과 비슷합니다.

    Waiting for Feature Service Mesh to be created...done.
    
  6. 프로젝트의 Fleet에 클러스터를 등록합니다.

    gcloud container fleet memberships register cluster-with-managed-asm-membership \
      --gke-cluster=us-central1-a/cluster-with-managed-asm \
      --enable-workload-identity \
      --project PROJECT_ID
    

    출력은 다음과 비슷합니다.

    Waiting for membership to be created...done.
    Created a new membership [projects/your-project-id/locations/global/memberships/cluster-with-gke-membership] for the cluster [cluster-with-gke-membership]
    Generating the Connect Agent manifest...
    Deploying the Connect Agent on cluster [cluster-with-gke-membership] in namespace [gke-connect]...
    Deployed the Connect Agent on cluster [cluster-with-gke-membership] in namespace [gke-connect].
    Finished registering the cluster [cluster-with-gke-membership] with the Fleet.
    
  7. 클러스터에서 관리형 Anthos Service Mesh를 사용 설정합니다.

    gcloud container fleet mesh update \
      --management automatic \
      --memberships cluster-with-managed-asm-membership \
      --project PROJECT_ID
    

    출력은 다음과 비슷합니다.

    Waiting for Feature Service Mesh to be updated...done.
    
  8. 관리형 Anthos Service Mesh가 클러스터에 프로비저닝되었고 사용할 준비가 되었는지 확인합니다.

    gcloud container fleet mesh describe --project PROJECT_ID
    

    Anthos Service Mesh가 프로비저닝되고 클러스터에서 사용할 수 있게 될 때까지 약 10분이 소요될 수 있습니다. controlPlaneManagement.state: DISABLED 또는 controlPlaneManagement.state: PROVISIONING이 표시되면 controlPlaneManagement.state: ACTIVE가 표시될 때까지 이전 명령어를 몇 분 간격으로 다시 실행해야 합니다.

    출력은 다음과 비슷합니다.

    createTime: '2022-07-06T01:05:39.110120474Z'
    membershipSpecs:
      projects/123456789123/locations/global/memberships/cluster-with-managed-asm-membership:
        mesh:
          management: MANAGEMENT_AUTOMATIC
    membershipStates:
      projects/123456789123/locations/global/memberships/cluster-with-managed-asm-membership:
        servicemesh:
          controlPlaneManagement:
            details:
            - code: REVISION_READY
              details: 'Ready: asm-managed'
            state: ACTIVE
          dataPlaneManagement:
            details:
            - code: OK
              details: Service is running.
            state: ACTIVE
        state:
          code: OK
          description: 'Revision(s) ready for use: asm-managed.'
          updateTime: '2022-07-06T01:19:24.243993678Z'
    name: projects/your-project-id/locations/global/features/servicemesh
    resourceState:
      state: ACTIVE
    spec: {}
    state:
      state: {}
    updateTime: '2022-07-06T01:19:27.475885687Z'
    

Anthos Service Mesh의 인그레스 게이트웨이 배포

  1. Anthos Service Mesh의 인그레스 게이트웨이를 asm-ingress라는 별도의 네임스페이스에 배포합니다. 네임스페이스를 만드세요.

    kubectl \
      --context cluster-with-managed-asm \
      create namespace asm-ingress
    
  2. istio.io/rev=asm-managed 라벨을 사용하여 asm-ingress 네임스페이스를 서비스 메시에 추가하고 자동 사이드카 프록시 삽입을 사용 설정합니다.

    kubectl \
      --context cluster-with-managed-asm \
      label namespace asm-ingress 'istio.io/rev=asm-managed'
    
  3. Anthos Service Mesh 인그레스 게이트웨이를 배포합니다.

    kubectl \
      --context cluster-with-managed-asm \
      --namespace=asm-ingress \
      apply -f anthos-service-mesh-samples/docs/shared/asm-ingress-gateway/asm-gateway-deployment-svc.yaml
    kubectl \
      --context cluster-with-managed-asm \
      --namespace=asm-ingress \
      apply -f anthos-service-mesh-samples/docs/shared/asm-ingress-gateway/gateway.yaml
    

    출력은 다음과 비슷합니다.

    namespace/asm-ingress configured
    serviceaccount/asm-ingressgateway configured
    service/asm-ingressgateway configured
    deployment.apps/asm-ingressgateway configured
    gateway.networking.istio.io/asm-ingressgateway configured
    

Online Boutique 배포

  1. Online Boutique를 onlineboutique라는 별도의 네임스페이스에 배포합니다. 네임스페이스를 만드세요.

    kubectl \
      --context cluster-with-managed-asm \
      create namespace onlineboutique
    
  2. istio.io/rev=asm-managed 라벨을 사용하여 onlineboutique 네임스페이스를 서비스 메시에 추가하고 자동 사이드카 프록시 삽입을 사용 설정합니다.

    kubectl \
      --context cluster-with-managed-asm \
      label namespace onlineboutique 'istio.io/rev=asm-managed'
    
  3. 사용자 트래픽을 모방하는 부하 생성기를 포함한 Online Boutique의 12개 서비스를 배포합니다.

    kubectl \
      --context cluster-with-managed-asm \
      --namespace=onlineboutique \
      apply -f anthos-service-mesh-samples/docs/shared/online-boutique/kubernetes-manifests.yaml
    kubectl \
      --context cluster-with-managed-asm \
      --namespace=onlineboutique \
      apply -f anthos-service-mesh-samples/docs/shared/online-boutique/virtual-service.yaml
    
  4. Anthos Service Mesh 인그레스 게이트웨이의 공개 IP 주소를 가져옵니다.

    kubectl \
      --context cluster-with-managed-asm \
      --namespace asm-ingress \
      get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'
    
  5. asm-ingressgateway 서비스의 공개 IP 주소를 복사하여 웹브라우저를 통해 액세스합니다. Online Boutique 샘플 앱이 표시됩니다. 다음 섹션에서 공개 IP 주소를 사용하므로 환경 변수에 복사합니다.

    export INGRESS_IP_OF_CLUSTER_WITH_MANAGED_ASM=$( \
      kubectl \
        --context cluster-with-managed-asm \
        --namespace asm-ingress \
        get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}' \
      )
    

카나리아 배포로 Anthos Service Mesh를 사용하는 클러스터 테스트

이 섹션에서는 Online Boutique의 사용자 트래픽 중 50%가 관리형 Anthos Service Mesh를 사용하는 클러스터의 Online Boutique 인스턴스로 이전되도록 Istio를 사용하는 클러스터를 구성합니다. 이를 위해 Istio를 사용하는 클러스터에 Istio 리소스 두 개를 배포합니다.

  • Istio에 관리형 Anthos Service Mesh 클러스터의 Online Boutique 엔드포인트를 알려주는 ServiceEntry
  • Istio 인그레스 게이트웨이에 트래픽을 50-50으로 분할하도록 지시하는 VirtualService
  1. ServiceEntry 리소스 내에서 관리형 Anthos Service Mesh 클러스터의 인그레스 게이트웨이의 IP 주소를 설정합니다.

    sed -i "s/1.2.3.4/${INGRESS_IP_OF_CLUSTER_WITH_MANAGED_ASM}/" anthos-service-mesh-samples/docs/migrate-to-managed-asm/service-entry.yaml
    
  2. Istio를 사용하는 클러스터에 ServiceEntry를 배포합니다.

    kubectl \
      --context cluster-with-istio \
      --namespace onlineboutique \
      apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/service-entry.yaml
    
  3. Istio를 사용하는 클러스터에 VirtualService를 배포합니다.

    kubectl \
      --context cluster-with-istio \
      --namespace onlineboutique \
      apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/virtual-service.yaml
    
  4. 웹브라우저에서 Istio가 있는 클러스터 인그레스 게이트웨이의 IP 주소로 이동합니다.

    kubectl \
      --context cluster-with-istio \
      --namespace istio-system \
      get service
    

    Online Boutique 홈페이지를 여러 번 새로고침하면서 페이지의 바닥글을 확인합니다. 요청의 50%가 관리형 Anthos Service Mesh를 사용하는 클러스터의 포드에서 처리되는 것을 알 수 있습니다.

관리형 Anthos Service Mesh를 사용하는 클러스터로 마이그레이션

이 섹션에서는 개발자가 도메인 이름을 소유하고 DNS(도메인 이름 서버) 설정에 액세스할 수 있다고 가정합니다.

  1. DNS 설정에 A 레코드를 추가하여 도메인 이름(예: example.com)이 Istio를 사용하는 클러스터에서 실행되는 인그레스 게이트웨이의 IP 주소를 가리키도록 합니다.

  2. 웹브라우저에서 도메인 이름으로 이동하여 Online Boutique에 액세스합니다.

  3. 롤백해야 하는 경우 DNS 항목을 빠르게 되돌릴 수 있도록 DNS 레코드 TTL(수명)을 최소화합니다.

  4. 도메인 이름의 A 레코드를 관리형 Anthos Service Mesh가 있는 클러스터의 인그레스 게이트웨이의 공개 IP 주소로 설정합니다.

  5. 마이그레이션이 완료되면 Istio를 사용하는 클러스터를 삭제합니다.

    gcloud container clusters delete cluster-with-istio \
      --zone=us-central1-a \
      --project=PROJECT_ID
    

삭제

이 튜토리얼에서 사용된 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 리소스가 포함된 프로젝트를 삭제하거나 프로젝트를 유지하고 개별 리소스를 삭제하세요.

프로젝트 삭제

  1. Google Cloud 콘솔에서 리소스 관리 페이지로 이동합니다.

    리소스 관리로 이동

  2. 프로젝트 목록에서 삭제할 프로젝트를 선택하고 삭제를 클릭합니다.
  3. 대화상자에서 프로젝트 ID를 입력한 후 종료를 클릭하여 프로젝트를 삭제합니다.

리소스 삭제

관리형 Anthos Service Mesh를 사용하는 클러스터를 삭제합니다.

  gcloud container clusters delete cluster-with-managed-asm \
    --zone=us-central1-a \
    --project=PROJECT_ID

다음 단계