Last active
March 22, 2023 13:37
-
-
Save NimJay/e44e6d9ce410689f88dea4fac2f8ed91 to your computer and use it in GitHub Desktop.
This is the most convenient, non-Terraform way I know to create a new Google Kubernetes Engine (GKE) cluster with managed Anthos Service Mesh (ASM) installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you're not using Cloud Shell, make sure to replace $GOOGLE_CLOUD_PROJECT with your Project ID. | |
# Cloud Shell is a small virtual machine (in Google Cloud) that's tied to your Google Cloud account. | |
export PROJECT_ID=$GOOGLE_CLOUD_PROJECT | |
export CLUSTER_NAME=my-cluster-3 | |
export KUBECONTEXT_NAME=my-cluster-3 | |
export ZONE=us-central1-b | |
export PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format='get(projectNumber)') | |
echo "๐๏ธ Enabling necessary Google Cloud APIs..." | |
gcloud services enable \ | |
anthos.googleapis.com \ | |
container.googleapis.com \ | |
gkehub.googleapis.com \ | |
mesh.googleapis.com | |
echo "โ๏ธ Creating a new Google Kubernetes Engine (GKE) cluster..." | |
# Note: Anthos Service Mesh requires Workload Identity to be enabled on the cluster. | |
gcloud container clusters create ${CLUSTER_NAME} \ | |
--project=${PROJECT_ID} --zone=${ZONE} \ | |
--machine-type=e2-standard-2 --num-nodes=3 \ | |
--workload-pool ${PROJECT_ID}.svc.id.goog \ | |
--labels mesh_id=proj-${PROJECT_NUMBER} | |
echo "โ๏ธ Renaming kubeconfig context of the cluster to ${CLUSTER_NAME}..." | |
kubectl config rename-context \ | |
gke_${PROJECT_ID}_${ZONE}_${CLUSTER_NAME} ${CLUSTER_NAME} | |
echo "๐ Enabling Anthos Service Mesh on the project's Fleet..." | |
gcloud container fleet mesh enable --project $PROJECT_ID | |
echo "๐ Register GKE Cluster to the project's Fleet..." | |
gcloud container fleet memberships register ${CLUSTER_NAME}-membership \ | |
--gke-cluster=${ZONE}/$CLUSTER_NAME \ | |
--enable-workload-identity \ | |
--project $PROJECT_ID | |
echo "๐ธ๏ธ Enabling managed Anthos Service Mesh on the cluster..." | |
gcloud container fleet mesh update \ | |
--management automatic \ | |
--memberships ${CLUSTER_NAME}-membership \ | |
--project ${PROJECT_ID} | |
# ----- A D D I T I O N A L I N F O ----- | |
# To configure Anthos Service Mesh to automatically inject Proxies to Pods in a namespace, use: | |
# kubectl label namespace MY_NAMESPACE istio-injection=enabled istio.io/rev- --overwrite | |
# To disable Anthos Service Mesh's managed data plane, annotate the namespace. | |
# The managed data plane is enabled by default. | |
# kubectl annotate --overwrite namespace YOUR_NAMESPACE mesh.cloud.google.com/proxy='{"managed":"true"}' | |
# To enable Workload Identity on an existing GKE cluster, use: | |
# Enable Workload Identity on the GKE cluster. This can take a few minutes. | |
# Also, note that existing pools of Nodes are unaffected. | |
# This only ensures that new Nodes will use Workload Identity. | |
# gcloud container clusters update ${CLUSTER_NAME} --zone=${ZONE} --workload-pool=${PROJECT_ID}.svc.id.goog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To verify that Anthos Service Mesh (ASM) has been installed, use:
You should see something similar to:
If you don't see it immediately, wait about 10 minutes.
Before I waited, my output was: