Memigrasikan bidang kontrol dalam cluster ke bidang kontrol terkelola di cluster baru
Tutorial ini menunjukkan cara memigrasikan aplikasi dari cluster Google Kubernetes Engine (GKE) menggunakan Cloud Service Mesh dalam cluster 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 Cloud Service Mesh dalam cluster dan gateway ingress Cloud Service Mesh di cluster. Cluster ini akan bertindak sebagai cluster yang ada yang ingin Anda migrasikan.
- Deploy contoh aplikasi Online Boutique ke cluster dengan Cloud Service Mesh dalam cluster.
- Buat cluster Google Kubernetes Engine lain, di project yang sama. Google Cloud
- Sediakan Cloud Service Mesh terkelola di cluster kedua dan deploy gateway ingress Cloud Service Mesh.
- Deploy Online Boutique ke cluster dengan Cloud Service Mesh terkelola untuk mereplikasi deployment dari cluster dengan Cloud Service Mesh dalam cluster.
- Alihkan 50% traffic pengguna dari cluster dengan Cloud Service Mesh dalam cluster ke cluster dengan Cloud Service Mesh terkelola, dengan menggunakan kemampuan pemisahan traffic Istio di cluster dengan Cloud Service Mesh dalam cluster.
- Selesaikan migrasi dari Cloud Service Mesh dalam cluster ke Cloud Service Mesh terkelola dengan mengarahkan entri sistem nama domain (DNS) cluster dengan Cloud Service Mesh dalam cluster ke cluster dengan Cloud Service Mesh terkelola.
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 Cloud Service Mesh dalam cluster ke Cloud Service Mesh terkelola:
- Migrasi bidang kontrol canary: Dalam strategi ini, Anda menyediakan Cloud Service Mesh terkelola di cluster yang sama dengan tempat Cloud Service Mesh dalam cluster 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-in-cluster-asm \ --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-in-cluster-asm \ cluster-with-in-cluster-asm
Periksa apakah konteks cluster telah diganti namanya:
kubectl config get-contexts --output="name"
Download versi yang menginstal Cloud Service Mesh 1.23.6 ke direktori kerja saat ini:
curl https://storage.googleapis.com/csm-artifacts/asm/asmcli_1.23 > asmcli
Anda akan diminta untuk mengetik "y", lalu tekan Enter.
Outputnya mirip dengan:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 167k 100 167k 0 0 701k 0 --:--:-- --:--:-- --:--:-- 701k
Buat agar skrip
asmcli
dapat dieksekusi:chmod +x asmcli
Instal Cloud Service Mesh dalam cluster menggunakan
asmcli
:./asmcli install \ --project_id PROJECT_ID \ --cluster_name cluster-with-in-cluster-asm \ --cluster_location us-central1-a \ --output_dir . \ --enable_all \ --ca mesh_ca
Mungkin perlu waktu beberapa menit hingga alat
asmcli
selesai. Alat ini menampilkan pesan informasi sehingga Anda dapat mengikuti progresnya.Jika berhasil, outputnya akan mirip dengan:
... asmcli: Successfully installed ASM.
Anda akan men-deploy gateway ingress Cloud Service Mesh ke namespace terpisah bernama
asm-ingress
. Buat namespace:kubectl \ --context cluster-with-in-cluster-asm \ create namespace asm-ingress
Gunakan label
istio.io/rev=asm-1236-11
untuk menambahkan namespaceasm-ingress
ke service mesh dan mengaktifkan injeksi proxy sidecar otomatis.kubectl \ --context cluster-with-in-cluster-asm \ label --overwrite namespace asm-ingress istio.io/rev=asm-1236-11
Outputnya mirip dengan:
namespace/asm-ingress labeled
Men-deploy gateway masuk Cloud Service Mesh:
kubectl \ --context cluster-with-in-cluster-asm \ --namespace=asm-ingress \ apply -f anthos-service-mesh-samples/docs/shared/asm-ingress-gateway/asm-gateway-deployment-svc.yaml kubectl \ --context cluster-with-in-cluster-asm \ --namespace=asm-ingress \ apply -f anthos-service-mesh-samples/docs/shared/asm-ingress-gateway/gateway.yaml
Outputnya mirip dengan:
serviceaccount/asm-ingressgateway created service/asm-ingressgateway created deployment.apps/asm-ingressgateway created gateway.networking.istio.io/asm-ingressgateway created
Anda akan men-deploy Butik Online ke namespace terpisah yang disebut
onlineboutique
. Buat namespace:kubectl \ --context cluster-with-in-cluster-asm \ create namespace onlineboutique
Gunakan label
istio.io/rev=asm-1236-11
untuk menambahkan namespaceonlineboutique
ke service mesh dan mengaktifkan injeksi proxy sidecar otomatis.kubectl \ --context cluster-with-in-cluster-asm \ label --overwrite namespace onlineboutique istio.io/rev=asm-1236-11
Outputnya mirip dengan:
namespace/onlineboutique labeled
Deploy 12 layanan Online Boutique, termasuk generator beban yang meniru traffic pengguna:
kubectl \ --context cluster-with-in-cluster-asm \ --namespace=onlineboutique \ apply -f anthos-service-mesh-samples/docs/shared/online-boutique/kubernetes-manifests.yaml kubectl \ --context cluster-with-in-cluster-asm \ --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-in-cluster-asm \ --namespace asm-ingress \ get service --output jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'
Salin alamat IP eksternal gateway ingress, 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 Cloud Service Mesh dalam cluster tentang endpoint Online Boutique cluster Cloud Service Mesh terkelola
- VirtualService untuk memberi tahu gateway masuk Cloud Service Mesh dalam cluster 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 Cloud Service Mesh dalam cluster:kubectl \ --context cluster-with-in-cluster-asm \ --namespace onlineboutique \ apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/service-entry.yaml
Deploy
VirtualService
ke cluster dengan Cloud Service Mesh dalam cluster:kubectl \ --context cluster-with-in-cluster-asm \ --namespace onlineboutique \ apply -f anthos-service-mesh-samples/docs/migrate-to-managed-asm/virtual-service-in-cluster-asm.yaml
Buka alamat IP gateway ingress cluster dengan Cloud Service Mesh dalam cluster, di browser web Anda:
kubectl \ --context cluster-with-in-cluster-asm \ --namespace asm-ingress \ 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 Cloud Service Mesh dalam cluster.
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 Cloud Service Mesh dalam cluster:
gcloud container clusters delete cluster-with-in-cluster-asm \ --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 Cloud Service Mesh dalam cluster
Buat cluster dan instal Cloud Service Mesh dalam cluster
Di bagian ini, Anda akan membuat cluster yang menggunakan Cloud Service Mesh dalam cluster. Dalam praktiknya, ini adalah cluster yang sudah Anda gunakan.
Men-deploy gateway traffic masuk Cloud Service Mesh
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 Cloud Service Mesh dalam cluster.
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 Cloud Service Mesh dalam cluster 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 Cloud Service Mesh dalam cluster:
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