https://www.cloudskillsboost.google/focuses/8459?locale=ja&parent=catalog
mac(Monterey 12.7)では、asmcli実行時「Segmentation fault: 11」エラーとなるので
Ubuntu 22.04で実施
-- 1. 前作業
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-452.0.1-linux-x86_64.tar.gz
tar -xf google-cloud-cli-452.0.1-linux-x86_64.tar.gz
gcloud init
gcloud auth list
gcloud --version
gcloud projects create project01-9999999 \
--name="project01"
gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet
gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111
gcloud services enable compute.googleapis.com --project project01-9999999
gcloud components update
-- 2. プロジェクトを設定する
gcloud config list
gcloud config set project project01-9999999
export PROJECT_ID=$(gcloud config get-value project)
export PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format="value(projectNumber)")
export CLUSTER_NAME=central
export CLUSTER_ZONE=us-west1-c
export WORKLOAD_POOL=${PROJECT_ID}.svc.id.goog
export MESH_ID="proj-${PROJECT_NUMBER}"
gcloud projects get-iam-policy $PROJECT_ID \
--flatten="bindings[].members" \
--filter="bindings.members:user:$(gcloud config get-value core/account 2>/dev/null)"
gcloud components install gke-gcloud-auth-plugin
gcloud components install kubectl
-- 3. GKE クラスタを設定する
gcloud config set compute/zone ${CLUSTER_ZONE}
gcloud services enable container.googleapis.com
gcloud services enable mesh.googleapis.com
gcloud container clusters create ${CLUSTER_NAME} \
--machine-type=n1-standard-4 \
--num-nodes=4 \
--workload-pool=${WORKLOAD_POOL} \
--enable-stackdriver-kubernetes \
--subnetwork=default \
--release-channel=regular \
--labels mesh_id=${MESH_ID}
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user=$(gcloud config get-value core/account 2>/dev/null)
-- 4. Anthos Service Mesh のインストールを準備する
cd
curl https://storage.googleapis.com/csm-artifacts/asm/asmcli_1.15 > asmcli
chmod +x asmcli
-- 5. Anthos Service Mesh の検証
sudo apt install jq
mkdir -p ~/asm_output
kubectl get namespace
kubectl create namespace istio-system
kubectl get namespace
./asmcli validate \
--project_id $PROJECT_ID \
--cluster_name $CLUSTER_NAME \
--cluster_location $CLUSTER_ZONE \
--fleet_id $PROJECT_ID \
--output_dir ~/asm_output
-- 6. Anthos Service Mesh をインストールする
-- 6.1 Anthos Service Mesh インストール
./asmcli install \
--project_id $PROJECT_ID \
--cluster_name $CLUSTER_NAME \
--cluster_location $CLUSTER_ZONE \
--fleet_id $PROJECT_ID \
--output_dir ./asm_output \
--enable_all \
--option legacy-default-ingressgateway \
--ca mesh_ca \
--enable_gcp_components
-- 6.2 Ingress ゲートウェイをインストールする
GATEWAY_NS=istio-gateway
kubectl create namespace $GATEWAY_NS
kubectl get deploy -n istio-system -l app=istiod -o \
jsonpath={.items[*].metadata.labels.'istio\.io\/rev'}'{"\n"}'
REVISION=$(kubectl get deploy -n istio-system -l app=istiod -o \
jsonpath={.items[*].metadata.labels.'istio\.io\/rev'}'{"\n"}')
kubectl label namespace $GATEWAY_NS \
istio.io/rev=$REVISION --overwrite
cd ~/asm_output
ls -lR samples/gateways/istio-ingressgateway
mv samples/gateways/istio-ingressgateway/autoscaling-v2beta1.yaml /tmp
ls -lR samples/gateways/istio-ingressgateway
kubectl apply -n $GATEWAY_NS \
-f samples/gateways/istio-ingressgateway
-- 6.3 サイドカー インジェクションを有効にする
kubectl label namespace default istio-injection-istio.io/rev=$REVISION --overwrite
-- 7. Istio 対応のマルチサービス アプリケーションである Bookinfo をデプロイする
-- 7.1 Bookinfo をデプロイする
cd istio-1.15.7-asm.23/
cat samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
-- 7.2 Istio Ingress ゲートウェイを使用して外部アクセスを有効にする
cat samples/bookinfo/networking/bookinfo-gateway.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
-- 7.3 Bookinfo のデプロイ状況を確認する
kubectl get services
kubectl get pods
kubectl exec -it $(kubectl get pod -l app=ratings \
-o jsonpath='{.items[0].metadata.name}') \
-c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
kubectl get gateway
kubectl get svc istio-ingressgateway -n istio-system
export GATEWAY_URL=192.0.2.1
curl -I http://${GATEWAY_URL}/productpage
-- 8. Bookinfo アプリケーションを使用する
-- 8.1 ウェブブラウザでアプリケーションを試す
-- 8.2 安定したバックグラウンドの負荷を生成する
sudo apt install siege
siege http://192.0.2.1/productpage
-- 9. Anthos Service Mesh ダッシュボードを使用してサービスのパフォーマンスを評価する
Anthosコンソール -> サービスメッシュ
-- 10. クリーンアップ
gcloud container clusters delete ${CLUSTER_NAME}
※ kubeクラスタはプロジェクトを削除しても課金され続けるため、明示的削除必要
gcloud projects list
gcloud projects delete project01-9999999 \
--quiet