Bermigrasi dari Istio 1.11 atau yang lebih baru ke Anthos Service Mesh

Tutorial ini menunjukkan cara memigrasikan aplikasi dari cluster Google Kubernetes Engine (GKE) menggunakan Istio ke cluster baru menggunakan Anthos Service Mesh terkelola — Mesh layanan yang sesuai dengan Istio dan terkelola sepenuhnya dari Google.

Dalam tutorial ini, Anda telah:

  1. Buat cluster Google Kubernetes Engine baru, lalu instal Istio dan gateway masuk Istio di cluster tersebut. Cluster ini akan bertindak sebagai cluster yang sudah ada dan ingin Anda migrasikan.
  2. Deploy aplikasi contoh Online Boutique ke cluster dengan Istio.
  3. Buat cluster Google Kubernetes Engine lain, di project Google Cloud yang sama.
  4. Aktifkan Anthos Service Mesh terkelola di cluster kedua dan deploy gateway ingress Anthos Service Mesh.
  5. Deploy Butik Online ke cluster dengan Anthos Service Mesh untuk mereplikasi deployment dari cluster dengan Istio.
  6. Alihkan 50% traffic pengguna dari cluster dengan Istio ke cluster yang menggunakan Anthos Service Mesh, dengan menggunakan kemampuan pemisahan traffic Istio di cluster dengan Istio.
  7. Selesaikan migrasi dari Istio ke Anthos Service Mesh dengan mengarahkan entri domain name system (DNS) pada cluster dengan Istio ke cluster tersebut dengan Anthos Service Mesh.

Traffic pengguna dibagi 50-50 antara cluster dengan Istio dan cluster dengan
Anthos Service Mesh. Setiap cluster berisi deployment OnlineBoutique-nya sendiri.

Deployment canary

"Canary deployment" adalah teknik yang digunakan dalam pengembangan software untuk menguji versi baru beberapa software sebelum merilis versi baru tersebut kepada semua pengguna. Metode ini meliputi peningkatan persentase traffic yang dikirim ke versi baru secara bertahap. Dalam tutorial ini, Anda akan menyiapkan cluster baru dengan Anthos Service Mesh terkelola dan secara bertahap mengalihkan traffic pengguna ke cluster tersebut. Anda akan mulai dengan mengarahkan 0% traffic pengguna ke cluster baru, lalu 50%, dan, terakhir, 100%. Dalam produksi, Anda harus menggunakan penambahan yang lebih kecil dan lebih banyak. Jika suatu saat Anda melihat bahwa cluster baru tidak dapat menangani persentase traffic, Anda dapat melakukan rollback dengan mengurangi persentasenya menjadi 0%.

Bidang kontrol Canary versus gugus canary

Ada dua strategi yang umum digunakan untuk migrasi dari Istio ke Anthos Service Mesh terkelola:

  • Migrasi bidang kontrol canary: Dalam strategi ini, Anda menyediakan Anthos Service Mesh terkelola di cluster yang sama tempat Istio terinstal saat ini.
  • Migrasi cluster canary: Dalam strategi ini, Anda akan membuat cluster baru, lalu menyediakan Anthos Service Mesh terkelola di cluster tersebut.

Dalam tutorial ini, Anda akan mempelajari strategi migrasi cluster canary.

Biaya

Tutorial ini menggunakan komponen Google Cloud yang dapat ditagih berikut:

Setelah menyelesaikan tutorial ini, Anda dapat menghindari biaya berkelanjutan dengan menghapus resource yang Anda buat. Untuk informasi selengkapnya, lihat Pembersihan.

Sebelum memulai

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  2. Di konsol Google Cloud, pada halaman pemilih project, pilih atau buat project Google Cloud.

    Buka pemilih project

  3. Pastikan penagihan telah diaktifkan untuk project Google Cloud Anda.

  4. Enable the required APIs.

    Enable the APIs

  5. Di konsol Google Cloud, pada halaman pemilih project, pilih atau buat project Google Cloud.

    Buka pemilih project

  6. Pastikan penagihan telah diaktifkan untuk project Google Cloud Anda.

  7. Enable the required APIs.

    Enable the APIs

Meluncurkan Cloud Shell

Dalam tutorial ini, Anda akan menggunakan Cloud Shell, yang merupakan lingkungan shell yang dihosting di Google Cloud untuk mengelola resource Google Cloud.

Cloud Shell telah diinstal dengan alat command line Google Cloud CLI, kubectl, dan istioctl. Gcloud CLI menyediakan CLI utama untuk Google Cloud.

Buka sesi Cloud Shell dari pojok kanan atas halaman ini, klik , lalu klik Acknowledge. Sesi Cloud Shell akan terbuka di dalam frame yang lebih rendah pada halaman. Selesaikan perintah berikut di sesi Cloud Shell tersebut.

Mendownload kode contoh

Clone repositori git yang berisi resource Kubernetes dan Istio yang akan Anda gunakan:

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

Menyiapkan cluster dengan Istio

Membuat cluster dan menginstal Istio

Di bagian ini, Anda akan membuat cluster yang menggunakan Istio. Dalam praktiknya, ini adalah cluster yang sudah Anda gunakan.

  1. Ganti PROJECT_ID dengan project ID Anda dan buat cluster baru:

    gcloud container clusters create cluster-with-istio \
      --project=PROJECT_ID \
      --zone=us-central1-a \
      --machine-type=e2-standard-2 --num-nodes=3
    
  2. Ganti nama konteks cluster agar cluster lebih mudah digunakan:

    kubectl config rename-context \
      gke_PROJECT_ID_us-central1-a_cluster-with-istio \
      cluster-with-istio
    
  3. Pastikan konteks cluster telah diganti namanya:

    kubectl config get-contexts --output="name"
    
  4. Instal Istio di cluster. Untuk mempermudah, Anda harus menginstal profil Istio default dan versi yang sesuai dengan penginstalan istioctl.

    istioctl install
    

    Anda akan diminta untuk mengetik "y", lalu tekan Enter.

    Outputnya mirip dengan:

    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.
    

Terapkan Butik Online

  1. Anda akan men-deploy Online Boutique ke namespace terpisah yang disebut onlineboutique. Buat namespace:

    kubectl \
      --context cluster-with-istio \
      create namespace onlineboutique
    
  2. Deploy layanan Online Boutique 12, yang mencakup generator beban yang meniru traffic pengguna:

    kubectl \
      --namespace=onlineboutique \
      --context=cluster-with-istio \
      apply -f microservices-demo/release/kubernetes-manifests.yaml
    
  3. Langkah sebelumnya juga men-deploy layanan yang disebut frontend-external (dari jenis LoadBalancer) yang akan diberi alamat IP publik. Namun, Anda hanya ingin mengizinkan traffic masuk publik melalui deployment gateway masuk Istio. Hapus resource layanan frontend-external:

    kubectl \
      --namespace=onlineboutique \
      --context=cluster-with-istio \
      delete service frontend-external
    
  4. Deploy resource Gateway Istio dan resource Istio VirtualService untuk traffic publik guna mengakses Online Boutique:

    kubectl \
      --namespace=onlineboutique \
      --context=cluster-with-istio \
      apply -f microservices-demo/istio-manifests/frontend-gateway.yaml
    
  5. Dapatkan alamat IP publik gateway ingress Istio:

    kubectl \
      --namespace istio-system \
      --context=cluster-with-istio \
      get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'
    
  6. Salin alamat IP publik layanan istio-ingressgateway, lalu akses melalui browser web Anda. Anda akan melihat contoh aplikasi Online Boutique.

Menyiapkan cluster baru dengan Anthos Service Mesh terkelola

Membuat cluster dan menyediakan Anthos Service Mesh terkelola

Di bagian ini, Anda akan membuat cluster yang akan menjadi tujuan migrasi. Anda akan menyediakan Anthos Service Mesh terkelola, dan men-deploy Online Boutique untuk mereplikasi deployment dari cluster yang menggunakan Istio.

  1. Simpan nomor Project Anda ke dalam variabel lingkungan:

    export PROJECT_NUMBER=$(gcloud projects \
      describe PROJECT_ID --format='get(projectNumber)')
    
  2. Membuat cluster baru:

    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. Ganti nama konteks cluster agar cluster lebih mudah digunakan:

    kubectl config rename-context \
      gke_PROJECT_ID_us-central1-a_cluster-with-managed-asm \
      cluster-with-managed-asm
    
  4. Pastikan konteks cluster telah diganti namanya:

    kubectl config get-contexts --output="name"
    
  5. Aktifkan Anthos Service Mesh di Armada project Anda. Fleet adalah pengelompokan logis cluster Kubernetes dan resource lain yang dapat dikelola bersama.

    gcloud container fleet mesh enable --project PROJECT_ID
    

    Outputnya mirip dengan:

    Waiting for Feature Service Mesh to be created...done.
    
  6. Daftarkan cluster ke Armada project:

    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
    

    Outputnya mirip dengan:

    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. Aktifkan Anthos Service Mesh terkelola di cluster:

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

    Outputnya mirip dengan:

    Waiting for Feature Service Mesh to be updated...done.
    
  8. Pastikan Anthos Service Mesh terkelola telah disediakan untuk cluster dan siap digunakan:

    gcloud container fleet mesh describe --project PROJECT_ID
    

    Diperlukan waktu sekitar 10 menit untuk menyediakan Anthos Service Mesh dan siap digunakan di cluster. Jika melihat controlPlaneManagement.state: DISABLED atau controlPlaneManagement.state: PROVISIONING, Anda perlu menjalankan kembali perintah sebelumnya setiap beberapa menit sampai Anda melihat controlPlaneManagement.state: ACTIVE.

    Outputnya mirip dengan:

    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'
    

Men-deploy gateway masuk Anthos Service Mesh

  1. Anda akan men-deploy gateway ingress Anthos Service Mesh ke namespace terpisah yang disebut asm-ingress. Buat namespace:

    kubectl \
      --context cluster-with-managed-asm \
      create namespace asm-ingress
    
  2. Gunakan label istio.io/rev=asm-managed untuk menambahkan namespace asm-ingress ke mesh layanan dan mengaktifkan injeksi proxy file bantuan otomatis.

    kubectl \
      --context cluster-with-managed-asm \
      label namespace asm-ingress 'istio.io/rev=asm-managed'
    
  3. Deploy gateway masuk 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
    

    Outputnya mirip dengan:

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

Terapkan Butik Online

  1. Anda akan men-deploy Online Boutique ke namespace terpisah yang disebut onlineboutique. Buat namespace:

    kubectl \
      --context cluster-with-managed-asm \
      create namespace onlineboutique
    
  2. Gunakan label istio.io/rev=asm-managed untuk menambahkan namespace onlineboutique ke mesh layanan dan mengaktifkan injeksi proxy sidecar otomatis.

    kubectl \
      --context cluster-with-managed-asm \
      label namespace onlineboutique 'istio.io/rev=asm-managed'
    
  3. Deploy layanan Online Boutique 12, termasuk generator beban yang meniru traffic pengguna:

    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. Dapatkan alamat IP publik gateway ingress Anthos Service Mesh:

    kubectl \
      --context cluster-with-managed-asm \
      --namespace asm-ingress \
      get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'
    
  5. Salin alamat IP publik Layanan asm-ingressgateway, lalu akses melalui browser web Anda. Anda akan melihat aplikasi contoh Online Boutique. Anda akan menggunakan alamat IP publik di bagian berikutnya, jadi salin alamat tersebut ke dalam variabel lingkungan:

    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}' \
      )
    

Menguji cluster dengan Anthos Service Mesh menggunakan deployment canary

Di bagian ini, Anda akan mengonfigurasi cluster dengan Istio sedemikian rupa sehingga 50% traffic pengguna ke Online Boutique dialihkan ke instance Online Boutique di cluster dengan Anthos Service Mesh terkelola. Untuk mencapainya, Anda men-deploy dua resource Istio ke cluster dengan Istio:

  • ServiceEntry untuk memberi tahu Istio tentang endpoint Online Boutique cluster Anthos Service Mesh terkelola
  • VirtualService untuk memberi tahu gateway ingress Istio untuk membagi traffic antara 50-50.
  1. Tetapkan alamat IP gateway masuk cluster Anthos Service Mesh terkelola di dalam resource ServiceEntry:

    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. Deploy ServiceEntry ke cluster dengan Istio:

    kubectl \
      --context cluster-with-istio \
      --namespace onlineboutique \
      apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/service-entry.yaml
    
  3. Deploy VirtualService ke cluster dengan Istio:

    kubectl \
      --context cluster-with-istio \
      --namespace onlineboutique \
      apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/virtual-service.yaml
    
  4. Buka alamat IP gateway masuk cluster dengan Istio, di browser web Anda:

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

    Muat ulang halaman beranda Butik Online beberapa kali, lalu periksa footer halaman setiap kali. Perhatikan bahwa 50% permintaan ditangani oleh Pod di cluster dengan Anthos Service Mesh terkelola.

Melakukan migrasi ke cluster dengan Anthos Service Mesh terkelola

Bagian ini mengasumsikan bahwa Anda memiliki nama domain dan memiliki akses ke setelan DNS (Domain Name Server)-nya.

  1. Tambahkan data A ke setelan DNS untuk mengarahkan nama domain (misalnya, example.com) ke alamat IP gateway masuk yang berjalan di cluster dengan Istio.

  2. Akses Butik Online dengan mengunjungi nama domain di browser web Anda.

  3. Minimalkan waktu aktif (TTL) data DNS untuk memastikan Anda dapat mengembalikan entri DNS dengan cepat jika perlu melakukan rollback.

  4. Setel data A nama domain Anda ke alamat IP publik gateway masuk cluster dengan Anthos Service Mesh terkelola.

  5. Setelah migrasi berhasil, hapus cluster dengan Istio:

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

Pembersihan

Agar tidak menimbulkan biaya pada akun Google Cloud Anda untuk resource yang digunakan dalam tutorial ini, hapus project yang berisi resource, atau pertahankan project dan hapus resource satu per satu.

Hapus project

  1. Di konsol Google Cloud, buka halaman Manage resource.

    Buka Manage resource

  2. Pada daftar project, pilih project yang ingin Anda hapus, lalu klik Delete.
  3. Pada dialog, ketik project ID, lalu klik Shut down untuk menghapus project.

Menghapus resource

Hapus cluster dengan Anthos Service Mesh terkelola:

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

Langkah selanjutnya