Jenkins Setup
I am using Jenkins LTS war file to deploy Jenkins, which is downloaded and deployed using jenkins.sh script which is present under jenkins folder.
The script perform below actions
- Download Jenkins.war file if not present in directory from which script is being run
- Start Jenkins with Java installed on local machine
JMeter Kubernetes Pipeline
Once Jenkins setup is complete we can configure Pipeline to perform actions to Perform Load test,
Pipeline has multiple steps as below:
- Cleanup of existing results\logs for new run
- Pull JMeter image that was created, if not please refer to link
- Get latest test script from repository(I used Github)
- Build JMeter Kubernetes Config for Master and Slaves
- Deploy JMeter Slaves in Kubernetes cluster
- Deploy JMeter Master in Kubernetes cluster and start test
- Stop JMeter Pods at end of test
- Archive test results for further reference
- Publish results to team
Note: Before we can execute the build we need to configure Grafana and Influx DB for live monitoring.
Below are the options that can be modified as per your requirement.
JMeter Container Image Config
Docker image to be used for JMeter Container karthiksurabathula/jmeter, the same image must be configured in kubernetes config from step 4.
stage('Pull Jmeter Image from registery') {
steps {
sh 'docker pull karthiksurabathula/jmeter'
}
}
Build Config Options - JMeter Script and Number of Nodes for Slaves
stage('Build Kubernetese Config') {
steps {
sh 'mkdir -p `pwd`/kubernetes-init/data/;cp `pwd`/data/script.jmx `pwd`/kubernetes-init/data/script.jmx;'
sh 'cd `pwd`/kubernetes-init/;chmod 775 create.sh;./create.sh 2 script.jmx'
}
}
In below I am copying script.jmx from git data folder to kubernetes-init/data folder as I configured JMeter pods to use it as persistence, you can add multiple files or copy all the files for JMeter test from git data folder to kubernetes-init\data folder.
cp `pwd`/data/script.jmx `pwd`/kubernetes-init/data/script.jmx;
In below step we are configuring number of slaves to be created for JMeter, I am creating "2" indicates two slaves and by one Master node will be created and JMeter script to be used is script.jmx. You can change script name to your preferred name
./create.sh 2 script.jmx'
Note: If script name is not specified JMeter container will be looking for script.jmx as default script as it is configured as part of launch.sh in step where we create docker container for JMeter.
Kubernetes Slave Instances Deployment Config:
Below stage starts JMeter slaves, number of slaves should be same as in earlier config above.
stage('Deploying Jmeter Slave Pods') {
steps {
sh 'cd `pwd`/kubernetes-init/config/; ls; i=1;while [ "$i" -le 2 ]; do microk8s kubectl apply -f slave$i.yaml; i=$(( i + 1 )); done'
}
}