Bermigrasi dari Istio 1.11 atau yang lebih baru ke Cloud Service Mesh
Tutorial ini menunjukkan cara memigrasikan aplikasi dari cluster Google Kubernetes Engine (GKE) menggunakan Istio ke cluster baru menggunakan Cloud Service Mesh terkelola — mesh layanan yang sepenuhnya terkelola dan kompatibel dengan Istio dari Google.
Dalam tutorial ini, Anda telah:
- Buat cluster Google Kubernetes Engine baru, lalu instal Istio dan gateway ingress Istio di cluster tersebut. Cluster ini akan bertindak sebagai cluster yang ada yang ingin Anda migrasikan.
- Deploy aplikasi contoh Online Boutique ke cluster dengan Istio.
- Buat cluster Google Kubernetes Engine lain, di project Google Cloud yang sama.
- Aktifkan Cloud Service Mesh terkelola di cluster kedua dan deploy gateway ingress Cloud Service Mesh.
- Deploy Online Boutique ke cluster dengan Cloud Service Mesh untuk mereplikasi deployment dari cluster dengan Istio.
- Alihkan 50% traffic pengguna dari cluster dengan Istio ke cluster dengan Cloud Service Mesh, dengan menggunakan kemampuan pemisahan traffic Istio di cluster dengan Istio.
- Selesaikan migrasi dari Istio ke Cloud Service Mesh dengan mengarahkan entri sistem nama domain (DNS) cluster dengan Istio ke cluster dengan Cloud Service Mesh.
Deployment canary
"Deployment canary" adalah teknik yang digunakan dalam pengembangan software untuk menguji versi baru software sebelum merilis versi baru tersebut kepada semua pengguna. Cara ini melibatkan peningkatan secara bertahap persentase traffic yang dikirim ke versi baru. Dalam tutorial ini, Anda akan menyiapkan cluster baru dengan Cloud Service Mesh terkelola dan secara bertahap mengalihkan traffic pengguna ke cluster tersebut. Anda akan memulai dengan mengarahkan 0% traffic pengguna ke cluster baru, lalu 50%, dan terakhir, 100%. Dalam produksi, Anda harus menggunakan kenaikan yang lebih kecil dan lebih banyak. Jika pada suatu saat Anda melihat bahwa cluster baru tidak dapat menangani persentase traffic, Anda dapat melakukan rollback dengan mengurangi persentase menjadi 0%.
Bidang kontrol canary versus cluster canary
Ada dua strategi yang umum digunakan untuk migrasi dari Istio ke Cloud Service Mesh terkelola:
- Migrasi cluster canary: Dalam strategi ini, Anda membuat cluster baru, lalu menyediakan Cloud Service Mesh terkelola di cluster tersebut.
- Migrasi bidang kontrol canary: Dalam strategi ini, Anda menyediakan Cloud Service Mesh terkelola di cluster yang sama tempat Istio diinstal. Ini bukan jalur migrasi yang didukung dengan Cloud Service Mesh.
Dalam tutorial ini, Anda akan mempelajari strategi migrasi cluster canary.
Biaya
Tutorial ini menggunakan komponen Google Cloudyang 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
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the required APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the required APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. Ganti
PROJECT_IDdengan 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=3Ganti nama konteks cluster agar cluster lebih mudah digunakan:
kubectl config rename-context \ gke_PROJECT_ID_us-central1-a_cluster-with-istio \ cluster-with-istioPeriksa apakah konteks cluster telah diganti namanya:
kubectl config get-contexts --output="name"Instal Istio di cluster. Untuk mempermudah, Anda akan menginstal profil Istio default dan versi yang cocok dengan penginstalan
istioctlAnda.istioctl installAnda 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.Anda akan men-deploy Online Boutique ke namespace terpisah yang disebut
onlineboutique. Buat namespace:kubectl \ --context cluster-with-istio \ create namespace onlineboutiqueDeploy 12 layanan Online Boutique, yang mencakup generator beban yang meniru traffic pengguna:
kubectl \ --namespace=onlineboutique \ --context=cluster-with-istio \ apply -f microservices-demo/release/kubernetes-manifests.yamlLangkah sebelumnya juga men-deploy layanan yang disebut
frontend-external(dari jenisLoadBalancer) yang diberi alamat IP eksternal. Namun, Anda hanya ingin mengizinkan traffic masuk publik melalui deployment gateway ingress Istio. Hapus resource layananfrontend-external:kubectl \ --namespace=onlineboutique \ --context=cluster-with-istio \ delete service frontend-externalDeploy resource
GatewayIstio dan resourceVirtualServiceIstio agar traffic publik dapat mengakses Butik Online:kubectl \ --namespace=onlineboutique \ --context=cluster-with-istio \ apply -f microservices-demo/istio-manifests/frontend-gateway.yamlDapatkan alamat IP eksternal gateway ingress Istio:
kubectl \ --namespace istio-system \ --context=cluster-with-istio \ get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'Salin alamat IP eksternal layanan
istio-ingressgateway, lalu akses melalui browser web Anda. Anda akan melihat aplikasi contoh Butik Online.Membuat cluster baru:
gcloud container clusters create cluster-with-csm \ --project=PROJECT_ID --zone=us-central1-a \ --machine-type=e2-standard-4 --num-nodes=2 \ --workload-pool PROJECT_ID.svc.id.googGanti nama konteks cluster agar cluster lebih mudah digunakan:
kubectl config rename-context \ gke_PROJECT_ID_us-central1-a_cluster-with-csm \ cluster-with-csmPeriksa apakah konteks cluster telah diganti namanya:
kubectl config get-contexts --output="name"Aktifkan Cloud Service Mesh di fleet project Anda. Fleet adalah pengelompokan logis cluster Kubernetes dan resource lain yang dapat dikelola bersama.
gcloud container fleet mesh enable --project PROJECT_IDOutputnya mirip dengan:
Waiting for Feature Service Mesh to be created...done.Daftarkan cluster ke fleet project:
gcloud container fleet memberships register cluster-with-csm-membership \ --gke-cluster=us-central1-a/cluster-with-csm \ --enable-workload-identity \ --project PROJECT_IDOutputnya mirip dengan:
Waiting for membership to be created...done. Finished registering to the Fleet.Aktifkan Cloud Service Mesh terkelola di cluster:
gcloud container fleet mesh update \ --management automatic \ --memberships cluster-with-csm-membership \ --project PROJECT_IDOutputnya mirip dengan:
Waiting for Feature Service Mesh to be updated...done.Pastikan bahwa Cloud Service Mesh terkelola telah disediakan untuk cluster dan siap digunakan:
gcloud container fleet mesh describe --project PROJECT_IDMungkin perlu waktu sekitar 10 menit agar Cloud Service Mesh dapat disediakan dan siap digunakan di cluster. Jika Anda melihat
controlPlaneManagement.state: DISABLEDataucontrolPlaneManagement.state: PROVISIONING, Anda harus menjalankan kembali perintah sebelumnya setiap beberapa menit hingga Anda melihatcontrolPlaneManagement.state: ACTIVE.Outputnya mirip dengan:
createTime: '2022-07-06T01:05:39.110120474Z' membershipSpecs: projects/123456789123/locations/global/memberships/cluster-with-csm-membership: mesh: management: MANAGEMENT_AUTOMATIC membershipStates: projects/123456789123/locations/global/memberships/cluster-with-csm-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'Anda akan men-deploy gateway ingress Cloud Service Mesh ke namespace terpisah yang disebut
asm-ingress. Buat namespace:kubectl \ --context cluster-with-csm \ create namespace asm-ingressGunakan label
istio.io/rev=asm-manageduntuk menambahkan namespaceasm-ingresske service mesh dan mengaktifkan injeksi proxy sidecar otomatis.kubectl \ --context cluster-with-csm \ label namespace asm-ingress 'istio.io/rev=asm-managed'Men-deploy gateway masuk Cloud Service Mesh:
kubectl \ --context cluster-with-csm \ --namespace=asm-ingress \ apply -f anthos-service-mesh-samples/docs/shared/asm-ingress-gateway/asm-gateway-deployment-svc.yaml kubectl \ --context cluster-with-csm \ --namespace=asm-ingress \ apply -f anthos-service-mesh-samples/docs/shared/asm-ingress-gateway/gateway.yamlOutputnya 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 configuredAnda akan men-deploy Online Boutique ke namespace terpisah yang disebut
onlineboutique. Buat namespace:kubectl \ --context cluster-with-csm \ create namespace onlineboutiqueGunakan label
istio.io/rev=asm-manageduntuk menambahkan namespaceonlineboutiqueke service mesh dan mengaktifkan injeksi proxy sidecar otomatis.kubectl \ --context cluster-with-csm \ label namespace onlineboutique 'istio.io/rev=asm-managed'Deploy 12 layanan Online Boutique, termasuk generator beban yang meniru traffic pengguna:
kubectl \ --context cluster-with-csm \ --namespace=onlineboutique \ apply -f anthos-service-mesh-samples/docs/shared/online-boutique/kubernetes-manifests.yaml kubectl \ --context cluster-with-csm \ --namespace=onlineboutique \ apply -f anthos-service-mesh-samples/docs/shared/online-boutique/virtual-service.yamlDapatkan alamat IP eksternal gateway masuk Cloud Service Mesh:
kubectl \ --context cluster-with-csm \ --namespace asm-ingress \ get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'Salin alamat IP eksternal Layanan
asm-ingressgateway, lalu akses melalui browser web Anda. Anda akan melihat aplikasi contoh Online Boutique. Anda akan menggunakan alamat IP eksternal di bagian berikutnya, jadi salin ke dalam variabel lingkungan:export INGRESS_IP_OF_CLUSTER_WITH_MANAGED_ASM=$( \ kubectl \ --context cluster-with-csm \ --namespace asm-ingress \ get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}' \ )- ServiceEntry untuk memberi tahu Istio tentang endpoint Online Boutique cluster Cloud Service Mesh terkelola
- VirtualService untuk memberi tahu gateway masuk Istio agar membagi traffic 50-50.
Tetapkan alamat IP gateway ingress cluster Managed Cloud Service Mesh 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.yamlDeploy
ServiceEntryke cluster dengan Istio:kubectl \ --context cluster-with-istio \ --namespace onlineboutique \ apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/service-entry.yamlDeploy
VirtualServiceke cluster dengan Istio:kubectl \ --context cluster-with-istio \ --namespace onlineboutique \ apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/virtual-service.yamlBuka alamat IP gateway ingress cluster dengan Istio di browser web Anda:
kubectl \ --context cluster-with-istio \ --namespace istio-system \ get serviceMuat ulang halaman beranda Online Boutique beberapa kali, dan periksa footer halaman setiap kali. Perhatikan bahwa 50% permintaan ditangani oleh Pod di cluster dengan Cloud Service Mesh terkelola.
Tambahkan data A ke setelan DNS untuk mengarahkan nama domain (seperti example.com) ke alamat IP gateway ingress yang berjalan di cluster dengan Istio.
Akses Online Boutique dengan membuka nama domain di browser web Anda.
Minimalkan time to live (TTL) data DNS untuk memastikan Anda dapat dengan cepat mengembalikan entri DNS jika perlu melakukan rollback.
Tetapkan data A nama domain Anda ke alamat IP eksternal gateway ingress cluster dengan Cloud Service Mesh terkelola.
Jika migrasi berhasil, hapus cluster dengan Istio:
gcloud container clusters delete cluster-with-istio \ --zone=us-central1-a \ --project=PROJECT_ID- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- Pelajari Managed Cloud Service Mesh.
- Pelajari praktik terbaik keamanan Cloud Service Mesh.
Meluncurkan Cloud Shell
Dalam tutorial ini, Anda akan menggunakan Cloud Shell, yang merupakan lingkungan shell yang dihosting di Google Cloud yang memungkinkan Anda mengelola resourceGoogle 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 terminal, lalu klik Acknowledge. Sesi Cloud Shell akan terbuka di dalam frame yang lebih rendah di halaman. Selesaikan perintah berikut dalam 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
Buat cluster dan instal Istio
Di bagian ini, Anda akan membuat cluster yang menggunakan Istio. Dalam praktiknya, ini akan menjadi cluster yang sudah Anda gunakan.
Men-deploy Online Boutique
Siapkan cluster baru dengan Cloud Service Mesh terkelola
Buat cluster dan sediakan Cloud Service Mesh terkelola
Di bagian ini, Anda akan membuat cluster yang akan dimigrasikan. Anda akan menyediakan Cloud Service Mesh terkelola, dan men-deploy Online Boutique untuk mereplikasi deployment dari cluster yang menggunakan Istio.
Men-deploy gateway traffic masuk Cloud Service Mesh
Men-deploy Online Boutique
Menguji cluster dengan Cloud Service Mesh menggunakan deployment canary
Di bagian ini, Anda akan mengonfigurasi cluster dengan Istio sehingga 50% traffic pengguna ke Online Boutique dialihkan ke instance Online Boutique di cluster dengan Cloud Service Mesh terkelola. Untuk melakukannya, Anda men-deploy dua resource Istio ke cluster dengan Istio:
Bermigrasi ke cluster dengan Cloud Service Mesh terkelola
Bagian ini mengasumsikan bahwa Anda memiliki nama domain dan memiliki akses ke setelan DNS (Domain Name Server) domain tersebut.
Pembersihan
Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan dalam tutorial ini, hapus project yang berisi resource tersebut, atau simpan project dan hapus setiap resource.
Hapus project
Menghapus resource
Hapus cluster dengan Cloud Service Mesh terkelola:
gcloud container clusters delete cluster-with-managed-asm \
--zone=us-central1-a \
--project=PROJECT_ID