You are currently viewing Running K6 using Google Cloud Build

Running K6 using Google Cloud Build

This tutorial shows you how you will be Running K6 using GCP. to create a continuous delivery pipeline using Google Kubernetes Engine (GKE), Cloud Source Repositories and Cloud Build. After you create a sample app, you configure these services to automatically build, test, and deploy it. When you modify the app code, the changes trigger the continuous delivery pipeline to automatically rebuild, retest, and redeploy the new version.

Running K6 involves 3 stages :

  1. Create a docker image and push it to the cloud repository
  2. Onboard Github on Cloud Build
  3. Create triggers

Let’s start with – Create a docker image and push it to the cloud repository

  1. You must have the google account to run the K6 tests using cloud build. Refer here
  2. To interact with google cloud from the terminal, you need to interact with kubectl API servers. To make this work, need to install gcloud SDK. Refer here
  3. Note : make sure you have completed both the above steps, to proceed further.
  4. Once you have all the required SDK and google account, You need below files to get started
    • Dockerfile
    • cloudbuild.yaml
    • K6 Script
  5. Get the above required files to be used for this exercise from here.
  6. Clone the repo and open the folder in any editor.
  7. Go through the Dockerfile and modify based on your requirement.
  8. Create an image out of the dockerfile – Run below command in the root of repo docker build -t test:k6

  1. The above command will create a base image against your Dockerfile.
  2. This base image needs to push to the google cloud repository, Use below command to push it to the gcr.
    • docker ps -a – This will give you the image created.
    • docker tag <imagename> k6:latest – This will tag your base image with the name k6.
    • docker push<Your cloud ProjectName>/k6:latest
  3. If you are unsure cloud project name use below command and this will return your project name which you can enter in command.

gcloud projects list

Sample Output

The push refers to repository [<Your cloud ProjectName>/k6]

a4974f6c41a8: Pushed

028a6b5f6661: Pushed

e57b0c314041: Layer already exists

dccc633e2921: Layer already exists

531743b7098c: Layer already exists

latest: digest: sha256:32e018d7b6915e6d948f638e77c073941722f1078f608c16af026ef3b6ccca01 size: 1365

  1. If you want to run the test locally using the image. Running K6 use below command.

docker run –rm -p<Your cloud ProjectName>/k6:latest

  1. Your next action is to run this build using google cloud image. Let’s proceed. If you do not want your test to be run with the deployment, skip all the below steps and Refer here.
  2. You need to create a deployment with the image [referring to the image which is already pushed in the gcr]. Rub below command.

kubectl create deployment baselinetest –<Your cloud ProjectName>/k6:latest

Sample Output :

deployment.apps/baselinetest created

  1. Create replica’s of your pods.

kubectl scale deployment baselinetest –replicas=3

Sample Output :

deployment.apps/baselinetest scaled

  1. Make autoscaling.

kubectl autoscale deployment baselinetest –cpu-percent=80 –min=1 –max=5

Sample Output :

horizontalpodautoscaler.autoscaling/baselinetest autoscaled

  1. Check all the pods

kubectl get pods

Sample Output :


baselinetest-75c4c4c8cb-p99qh 0/1 ImagePullBackOff 0 105s

baselinetest-75c4c4c8cb-sllbj 0/1 ErrImagePull 0 39s

baselinetest-75c4c4c8cb-wjxjr 0/1 ErrImagePull 0 39s

  1. Now its time to integrate the cloud build with github. Refer here.

About the Author

Pawan Sinha is a blogger whose interests in writing blogs on a day to day issues for any engineer working for a software company. To discuss his work, He has a background in Testing/DevOps/Engineering/Cloud/AWS/GCP. His portfolio.

This Post Has One Comment

Leave a Reply