Deploying the Spanner Adaptor on Google Kubernetes Engine (GKE) facilitates seamless communication between your application and Google Cloud Spanner. Below is an overview of the major steps involved in the deployment process.
Ensure you have the following before getting started:
- GCP Editor Role Permissions:
- Obtain the GCP Editor role permissions to manage resources on Google Cloud Platform.
- kubectl CLI:
- Install
kubectl
CLI for Kubernetes cluster deployment. Follow the Kubernetes Documentation for installation instructions.
- Install
- Docker:
- Build docker image and push to Artifact Registry.
Clone the repository:
git clone [email protected]:cldcvr/cassandra-to-spanner-proxy.git
Prepare Google Cloud CLI Config:
export PROJECT_ID=<project_id>
export REGION=<region>
gcloud auth application-default login --project $PROJECT_ID
gcloud config set project $PROJECT_ID
Retrieve values from the Terraform output and export them as environment variables:
terraform output
export SERVICE_ACCOUNT="spanner-adaptor-proxy-sa-dev@<project_id>.iam.gserviceaccount.com"
export ARTIFACT_REGISTRY="spanner-adaptor-docker-dev"
export APP_NAME="spanner-adaptor"
export PROXY_VM_NAME="kubectl-proxy-vm-dev"
export GKE_CLUSTER="spanner-adaptor-gke-dev"
Configure Google Cloud Artifact Registry:
gcloud auth configure-docker $REGION-docker.pkg.dev
Build and Push Docker Image:
cd cassandra-to-spanner-proxy
docker build --platform linux/amd64 -t $REGION-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_REGISTRY/"$APP_NAME":tag1 .
docker push $REGION-docker.pkg.dev/$PROJECT_ID/$ARTIFACT_REGISTRY/"$APP_NAME":tag1
Create a JSON Key for Google Cloud Service Account:
gcloud iam service-accounts keys create --iam-account "$SERVICE_ACCOUNT@$PROJECT_ID.iam.gserviceaccount.com"~/Downloads/spanner-adaptor-service-account.json
Modify the YAML file: like GOOGLE_APPLICATION_CREDENTIALS
, SPANNER_DB_NAME
and SPANNER_NUM_CHANNELS
vi spanner-deployment.yaml
Make the necessary updates in the file and save the changes.
Use the kubectl-proxy-vm-dev
to connect to the Private GKE Cluster:
gcloud container clusters get-credentials $GKE_CLUSTER --region $REGION --project $PROJECT_ID
gcloud compute ssh $PROXY_VM_NAME --tunnel-through-iap --project=$PROJECT_ID --zone=${REGION}-a --ssh-flag="-4 -L8888:localhost:8888 -N -q -f"
export HTTPS_PROXY=localhost:8888
kubectl get pod -A
Unset IAP Tunneling:
gcloud config unset proxy/type
gcloud config unset proxy/address
gcloud config unset proxy/port
unset HTTPS_PROXY
unset HTTP_PROXY
Create Secrets:
kubectl create namespace deployment
kubectl create secret generic app-secret-sa -n deployment \
--from-file ~/Downloads/<spanner-adaptor-service-account-json-file-name>
Once GKE cluster access is obtained, proceed with the deployment:
cd k8/
kubectl apply -f spanner-deployment.yaml