Skip to content

bastiandg/scaling-in-the-cloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scaling Talk

General setup

  • install packer
  • install terraform
  • install kubectl
  • install gcloud
  • install a benchmarking tool / load generator (the examples use hey)
  • create service account
  • assign roles:
    • "Compute Admin" (roles/compute.admin) - for creating VM instances, disks, images and load balancers
    • "Service Account User" (roles/iam.serviceAccountUser) - for using the compute and k8s service accounts
    • "Cloud Build Editor" (roles/cloudbuild.builds.editor) - for starting cloud builds
    • "Storage Admin" (roles/storage.admin) - for creating a bucket the cloud build needs
    • "Cloud Run Admin" (roles/run.admin) - for deploying to cloud run
    • "Kubernetes Engine Admin" (roles/container.admin) - for deploying kubernetes clusters
  • Enable the APIs:
    • "Compute Engine Api" (compute.googleapis.com)
    • "Cloud Run API" (run.googleapis.com)
    • "Kubernetes Engine API" (container.googleapis.com)
    • "Cloud Build API" (cloudbuild.googleapis.com)
  • create and download credentials file for the account
  • customize and load the variables
    cp env.sh.example env.sh
    editor env.sh # change project_id and credentials location
    . env.sh

VM example

Setup

cd vm/
packer build image.json # creates a vm base image
terraform init          # initializes terraform
terraform plan          # shows resources terraform will create
terraform apply         # applies resources
sleep 300               # Wait for the Instances and the load balancer to be up

Scaling test

export service_ip="$(terraform output vm_lb_ip_address)"
hey -q 20 -c 20 -n 2000 "http://$service_ip/"

After around 30 - 60 seconds the scaling will set in.

Kubernetes

build image

cd k8s/
# Create a docker image of the service
gcloud builds submit ../service/ --project "$project_id" --config cloudbuild.yaml --substitutions "_SERVICE_NAME=$service_name" --async

deploy kubernetes cluster

cd k8s/
# Set up the terraform cluster
terraform init
terraform plan
terraform apply

deploy hashy service

# Setup kubectl config for cluster
gcloud container clusters get-credentials hashy-cluster --zone "$zone" --project "$project_id"

kubectl get nodes # show kubernetes nodes
envsubst < deployment.yaml | kubectl apply -f - # deploy application
envsubst < service.yaml | kubectl apply -f - # create a service
envsubst < autoscaler.yaml | kubectl apply -f - # create an auto scaling object

Scaling test

kubectl get services
export service_ip="$(kubectl get services "$service_name" -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
hey -q 20 -c 20 -n 2000 "http://$service_ip/"
watch kubectl get nodes # this has to be opened in another window

Cloud Run

Build image

gcloud builds submit ../service/ --project "$project_id" --config cloudbuild.yaml --substitutions "_SERVICE_NAME=$service_name" --async

Deployment

gcloud run deploy hashy --concurrency=1 --allow-unauthenticated --image="gcr.io/${project_id}/${service_name}-image" --platform managed --region europe-west1

Scaling test

export RUN_URL="$(gcloud run services describe "$service_name" --region "$cloud_run_region" --format='value(status.url)' --platform managed)"
bash hey.sh

Links

About

Scaling tech talk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published