I have set up elastic search using official Elastic Search Helm chart I followed below steps
Created cluster as below
gcloud container clusters create cluster-1 --enable-autoscaling --zone us-central1-c \ --num-nodes 2 \ --min-nodes 1 \ --max-nodes 5
used custom values.yaml for installing elastic search.
helm install elasticsearch elastic/elasticsearch -f ./values.yaml
values.yaml
replicas: 1
# Shrink default JVM heap.
esJavaOpts: "-Xmx128m -Xms128m"
# Allocate smaller chunks of memory per pod.
resources:
requests:
cpu: "100m"
memory: "512M"
limits:
cpu: "200m"
memory: "512M"
# Request smaller persistent volumes.
volumeClaimTemplate:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "standard"
resources:
requests:
storage: 500M
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- elasticsearch.mydomain.com
Created index and inserted document it elastic db.
curl -X PUT "http://elasticsearch.mydomain.com/company" -H 'Content-Type: application/json' -d' { "settings": { "number_of_shards": 1, "number_of_replicas": 1 }, "mappings": { "properties": { "age": { "type": "integer"}, "experienceInYears": {"type": "integer" }, "name": {"type": "text"} } } } '
curl -X PUT "http://elasticsearch.mydomain.com/company/_doc/1" -H 'Content-Type: application/json' -d' { "name": "John", "age" : 30, "experienceInYears" : 6 } '
Now I want to send bulk search request to generate load on elastic search pod. So I written below shell script and tried to execute from multiple terminal.
`
#!/bin/bash
i=0 # set counter to 0
while true # infinite loop
do
curl -X GET "http://elasticsearch.mydomain.com/company/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : { "name" : "John" }
}
}'
if [ $? -ne 0 ]
then
# curl didn't return 0 - failure
echo $i
break # terminate loop
fi
i=$(($i+1)) # increment counter
echo -en "$i \r" # display # of requests each iteration
sleep 0.25 # short pause between requests
done
`
Now as I am sending bulk request new node should get created (kubernetes cluster auto scaling), but its showing only 2 nodes. May be because cpu limit of 200m is not crossed.
kubectl get nodes NAME STATUS ROLES AGE VERSION gke-cluster-1-default-pool-d6891b13-flf9 Ready <none> 18h v1.14.10-gke.36 gke-cluster-1-default-pool-d6891b13-hw2x Ready <none> 18h v1.14.10-gke.36 kubectl top pods NAME CPU(cores) MEMORY(bytes) elasticsearch-master-0 160m 371Mi ingress-elastic-search-test-ingress-nginx-controller-5c96ctthr2 25m 68Mi
So how to auto scale elastic search cluster based on load. How to generate load on elastic search pods ?