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 yang sama. Google Cloud
- 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 tertentu sebelum merilis versi baru tersebut kepada semua pengguna. Proses 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 bidang kontrol canary: Dalam strategi ini, Anda menyediakan Cloud Service Mesh terkelola di cluster yang sama tempat Istio diinstal.
- Migrasi cluster canary: Dalam strategi ini, Anda membuat cluster baru, lalu menyediakan Cloud 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: Google Cloud
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.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the required APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the required APIs.
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
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
Periksa 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
istioctl
Anda.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.
Anda akan men-deploy Butik Online ke namespace terpisah yang disebut
onlineboutique
. Buat namespace:kubectl \ --context cluster-with-istio \ create namespace onlineboutique
Deploy 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.yaml
Langkah sebelumnya juga men-deploy layanan yang disebut
frontend-external
(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-external
Deploy resource
Gateway
Istio dan resourceVirtualService
Istio agar traffic publik dapat mengakses Butik Online:kubectl \ --namespace=onlineboutique \ --context=cluster-with-istio \ apply -f microservices-demo/istio-manifests/frontend-gateway.yaml
Dapatkan 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.goog
Ganti nama konteks cluster agar cluster lebih mudah digunakan:
kubectl config rename-context \ gke_PROJECT_ID_us-central1-a_cluster-with-csm \ cluster-with-csm
Periksa 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_ID
Outputnya 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_ID
Outputnya 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_ID
Outputnya 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_ID
Mungkin perlu waktu sekitar 10 menit agar Cloud Service Mesh dapat melakukan penyediaan dan siap digunakan di cluster. Jika Anda melihat
controlPlaneManagement.state: DISABLED
ataucontrolPlaneManagement.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 bernama
asm-ingress
. Buat namespace:kubectl \ --context cluster-with-csm \ create namespace asm-ingress
Gunakan label
istio.io/rev=asm-managed
untuk menambahkan namespaceasm-ingress
ke 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.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
Anda akan men-deploy Butik Online ke namespace terpisah yang disebut
onlineboutique
. Buat namespace:kubectl \ --context cluster-with-csm \ create namespace onlineboutique
Gunakan label
istio.io/rev=asm-managed
untuk menambahkan namespaceonlineboutique
ke 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.yaml
Dapatkan 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.yaml
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
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
Buka alamat IP gateway ingress cluster dengan Istio di browser web Anda:
kubectl \ --context cluster-with-istio \ --namespace istio-system \ get service
Muat 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 Setuju. Sesi Cloud Shell akan terbuka di dalam frame yang lebih rendah di 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
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
Uji 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 tidak dikenai biaya pada akun Google Cloud Anda untuk resource yang digunakan dalam tutorial ini, hapus project yang berisi resource tersebut, atau simpan project dan hapus setiap resource.
Hapus project
Menghapus resource
Menghapus cluster dengan Cloud Service Mesh terkelola:
gcloud container clusters delete cluster-with-managed-asm \
--zone=us-central1-a \
--project=PROJECT_ID