- Distributed load testing with GKE
NOTE The below instructions to for multi instance load operations deploy as a kubernetes deployment. This means that kubernetes will continuously restart your load or run instances until you manually stop them. It is important that you do not leave them running indefinitely.
export PROJECT_ID=spanner-test
export SPANNER_INSTANCE=test-instance
export SPANNER_DATABASE=test-database
export GKE_CLUSTER_NAME=test-cluster
export GCP_REGION=us-west2
gcloud projects create $PROJECT_ID
gcloud services enable spanner.googleapis.com --project $PROJECT_ID
gcloud services enable cloudbuild.googleapis.com --project $PROJECT_ID
gcloud services enable container.googleapis.com --project $PROJECT_ID
gcloud services enable artifactregistry.googleapis.com --project $PROJECT_ID
gcloud iam service-accounts create gcsb-test-sa \
--description="GCSB Test Account" \
--display-name="gcsb" \
--project $PROJECT_ID
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:gcsb-test-sa@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/spanner.databaseUser"
gcloud iam service-accounts keys create key.json --iam-account=gcsb-test-sa@${PROJECT_ID}.iam.gserviceaccount.com
gcloud alpha spanner instances create $SPANNER_INSTANCE --config=regional-us-east1 --processing-units=1000 --project $PROJECT_ID
gcloud spanner databases create $SPANNER_DATABASE --instance=$SPANNER_INSTANCE --project $PROJECT_ID
Please see gcloud compute machine-types list
for a list of machine types
gcloud container clusters create $GKE_CLUSTER_NAME \
--project $PROJECT_ID \
--region $GCP_REGION \
--machine-type=n1-standard-8 \
--num-nodes 3
kubectl create secret generic gcsb-sa-key --from-file=key.json=./key.json
gcloud builds submit --tag gcr.io/$PROJECT_ID/gcsb .
To run inside Kubernetes, you will need to mount the ServiceAccount key secret into the container. Additionally, you will need to set the environment variable GOOGLE_APPLICATION_CREDENTIALS
pointing to this key file. Below, there are instructions for single container launches versus parallel launches.
If you want to simply run a single instance of gcsb to perform a load operation, you can launch a POD via the kubectl run
command.
kubectl run gcsb-load \
--image=gcr.io/$PROJECT_ID/gcsb \
--replicas=1 \
--restart=Never \
--overrides='{
"apiVersion": "v1",
"spec": {
"containers": [{
"name": "gcsb-load",
"image": "gcr.io/'$PROJECT_ID'/gcsb",
"command": [ "/gcsb", "load" ],
"args": [ "--project='$PROJECT_ID'", "--instance='$SPANNER_INSTANCE'", "--database='$SPANNER_DATABASE'", "--table=SingleSingers", "--operations=1000000"],
"volumeMounts": [{"mountPath": "/var/secrets/google", "name": "google-cloud-key"}],
"env": [{ "name": "GOOGLE_APPLICATION_CREDENTIALS", "value": "/var/secrets/google/key.json" }]
}],
"volumes": [ { "name": "google-cloud-key", "secret": { "secretName": "gcsb-sa-key" } } ]
}
}'
To create a load operation named 'gcsb-load', you must edit the gke_load.yaml file, supplying your spanner information.
For example, everywhere you se the comment EDIT:
you must specify your information.
- --project=YOUR_PROJECT_ID # EDIT: Your GCP Project ID
- --instance=YOUR_INSTANCE_ID # EDIT: Your Spanner Instance ID
- --database=YOUR_DATABASE # EDIT: Your Spanner Database Name
- --table=YOUR_TABLE # EDIT: Your Table Name
- --operations=1000000 # EDIT: Number of Operations
- --threads=10 # EDIT: Number of Threads
Once you have completed the necessary file edits, run the following.
kubectl apply -f docs/gke_load.yaml
to stop the test
kubectl delete deploy gcsb-load
If you want to simply run a single instance of gcsb to perform a run operation, you can launch a POD via the kubectl run
command.
kubectl run gcsb-load \
--image=gcr.io/$PROJECT_ID/gcsb \
--replicas=1 \
--restart=Never \
--overrides='{
"apiVersion": "v1",
"spec": {
"containers": [{
"name": "gcsb-load",
"image": "gcr.io/'$PROJECT_ID'/gcsb",
"command": [ "/gcsb", "run" ],
"args": [ "--project='$PROJECT_ID'", "--instance='$SPANNER_INSTANCE'", "--database='$SPANNER_DATABASE'", "--table=SingleSingers", "--operations=1000000"],
"volumeMounts": [{"mountPath": "/var/secrets/google", "name": "google-cloud-key"}],
"env": [{ "name": "GOOGLE_APPLICATION_CREDENTIALS", "value": "/var/secrets/google/key.json" }]
}],
"volumes": [ { "name": "google-cloud-key", "secret": { "secretName": "gcsb-sa-key" } } ]
}
}'
To create a load operation named 'gcsb-run', you must edit the gke_run.yaml file, supplying your spanner information.
For example, everywhere you se the comment EDIT:
you must specify your information.
- --project=YOUR_PROJECT_ID # EDIT: Your GCP Project ID
- --instance=YOUR_INSTANCE_ID # EDIT: Your Spanner Instance ID
- --database=YOUR_DATABASE # EDIT: Your Spanner Database Name
- --table=YOUR_TABLE # EDIT: Your Table Name
- --operations=1000000 # EDIT: Number of Operations
- --threads=10 # EDIT: Number of Threads
- --reads=50 # EDIT: Read Weight (Example: 50 = 50% reads)
- --writes=50 # EDIT: Write Weight (Example: 50 = 50% writes)
- --sample-size=5 # EDIT: Percentage of table to sample for generating reads (Example: 5 = 5% of the rows in the table)
Once you have completed the necessary file edits, run the following.
kubectl apply -f docs/gke_run.yaml
to stop the test
kubectl delete deploy gcsb-run
If you prefer to mount your custom gcsb file into the container, you should follow these instructions
The below example assumes your conig file is named gcsb.yaml
kubectl create configmap gcsb-config --from-file=gcsb.yaml
To create a load operation named 'gcsb-load', you must edit the gke_load_custom.yaml file, supplying your spanner information.
For example, everywhere you se the comment EDIT:
you must specify your information.
- --table=YOUR_TABLE # EDIT: Your Table Name
Once you have completed the necessary file edits, run the following.
kubectl apply -f docs/gke_load_custom.yaml
to stop the test
kubectl delete deploy gcsb-load
To create a load operation named 'gcsb-run', you must edit the gke_run_custom.yaml file, supplying your spanner information.
For example, everywhere you se the comment EDIT:
you must specify your information.
- --table=YOUR_TABLE # EDIT: Your Table Name
Once you have completed the necessary file edits, run the following.
kubectl apply -f docs/gke_run_custom.yaml
to stop the test
kubectl delete deploy gcsb-run
SchemaError(io.k8s.api.autoscaling.v2beta2.MetricTarget): invalid object doesn't have additional properties
There are issues with some kubectl installations from homebrew. Please relink your kubectl installation by following these instructions.