elasticsearch
by apecloud
Elasticsearch is a distributed, RESTful search engine optimized for speed and relevance on production-scale workloads.
About this chart
Elasticsearch
Elasticsearch is a distributed, RESTful search engine optimized for speed and relevance on production-scale workloads. Each Elasticsearch cluster consists of one or more nodes, and each node in a cluster has a role and communicates with other nodes to share data and responsibilities. A node can assume multiple roles up to your requirements. Types of roles include [^1]:
- master
- data
- data_content
- data_hot
- data_warm
- data_cold
- data_frozen
- ingest
- ml
- remote_cluster_client
- transform
Features In KubeBlocks
Lifecycle Management
| Horizontalscaling | Vertical scaling | Expandvolume | Restart | Stop/Start | Configure | Expose | Switchover |
|---|---|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | No | Yes | N/A |
Versions
| Major Versions | Description |
|---|---|
| 7.x | 7.7.1,7.8.1,7.10.1,7.10.2 |
| 8.x | 8.1.3, 8.8.2 |
Prerequisites
-
Kubernetes cluster >= v1.21
-
kubectlinstalled, refer to K8s Install Tools -
Helm, refer to Installing Helm
-
KubeBlocks installed and running, refer to Install Kubeblocks
-
Elasticsearch Addon Enabled, refer to Install Addons
-
Create K8s Namespace
demo, to keep resources created in this tutorial isolated:kubectl create ns demo
Examples
Create
Create a Single-Node Cluster
A Single-Node Cluster is a cluster with only one node and this node assume all roles. It is suitable for development and testing purposes.
# cat examples/elasticsearch/cluster-single-node.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: es-singlenode
namespace: demo
spec:
terminationPolicy: Delete
componentSpecs:
- name: mdit
componentDef: elasticsearch-8
serviceVersion: 8.8.2
replicas: 1
configs:
- name: es-cm
variables:
mode: "single-node"
resources:
limits:
cpu: "1"
memory: "2Gi"
requests:
cpu: "1"
memory: "2Gi"
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
kubectl apply -f examples/elasticsearch/cluster-single-node.yaml
The configs in Cluster API:
configs:
- name: es-cm
variables:
mode: "single-node"
Where,
es-cmrefers to the config template defined in ComponentDefinitionelasticsearch-- "mode=single-node" (default to multi-node), is used to specify the mode of the Elasticsearch cluster.
To check the role of the node, you may log in to the pod and run the following command:
curl -X GET "http://localhost:9200/_cat/nodes?v&h=name,ip,role"
And the expected output is as follows:
name ip role
es-single-node-mdit-0 12.345.678 cdfhilmrstw
The role is cdfhilmrstw. Please refer to Elasticsearch Nodes for more information about the roles.
Create a Multi-Node Cluster
Create a elasticsearch cluster with multiple nodes and each node assume specified roles.
# cat examples/elasticsearch/cluster-multi-node.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: es-multinode
namespace: demo
spec:
terminationPolicy: Delete
componentSpecs:
- name: master
componentDef: elasticsearch-master-8
serviceVersion: 8.8.2
configs:
- name: es-cm
variables:
version: 8.8.2
replicas: 3
resources:
limits:
cpu: "1"
memory: "2Gi"
requests:
cpu: "1"
memory: "2Gi"
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: data
componentDef: elasticsearch-data-8
serviceVersion: 8.8.2
configs:
- name: es-cm
variables:
version: 8.8.2
replicas: 3
resources:
limits:
cpu: "1"
memory: "2Gi"
requests:
cpu: "1"
memory: "2Gi"
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
kubectl apply -f examples/elasticsearch/cluster-multi-node.yaml
There are four components specified in this cluster, i.e 'master', 'data', 'ingest', and 'transform', and each component has different roles. Roles are specified in configs for each component:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
spec:
componentSpecs:
- name: data
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: data,ingest,transform
mode: multi-node
...
- name: master
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: master
mode: multi-node
Where,
es-cmrefers to the config template defined in ComponentDefinitionelasticsearch-- "mode=multi-node" (default to multi-node), is used to specify the mode of the Elasticsearch cluster.
- "roles: data,ingest,transform" specifies the list of roles this component should assume.
[!IMPORTANT]
- Roles will take effect only when
modeis set tomulti-node, or themodeis not set.- there must be one and only one component containing role 'master'
- the component for role
matermust be named tomaster
If you want to create a cluster with more roles, you can add more components and specify the roles in the configs.
spec:
terminationPolicy: Delete
componentSpecs:
- name: master
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: master
- name: data
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: data
- name: ingest
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: ingest
- name: transform
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: transform
...
Horizontal scaling
Scale-out
Horizontal scaling out elasticsearch cluster by adding ONE MASTER replica:
# cat examples/elasticsearch/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: es-scale-out
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: es-multinode
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
# - master
# - data
# - ingest
# - transform
- componentName: master
# Specifies the replica changes for scaling in components
scaleOut:
# Specifies the replica changes for the component.
# add one more replica to current component
replicaChanges: 1
kubectl apply -f examples/elasticsearch/scale-out.yaml
Scale-in
Horizontal scaling in elasticsearch cluster by deleting ONE MASTER replica:
# cat examples/elasticsearch/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: es-scale-in
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: es-multinode
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
# - master
# - data
# - ingest
# - transform
- componentName: master
# Specifies the replica changes for scaling in components
scaleIn:
# Specifies the replica changes for the component.
# add one more replica to current component
replicaChanges: 1
kubectl apply -f examples/elasticsearch/scale-in.yaml
On scaling in, the pod with the highest ordinal number (if not otherwise specified) will be deleted. And it will be cleared from voting configuration exclusions of this cluster before deletion, to make sure the cluster is healthy.
After scaling in, you can check the cluster health by running the following command:
curl -X GET "http://<ES_ENDPOINT>:9200/_cluster/health?pretty" # replace <ES_ENDPOINT> with the actual endpoint
[!IMPORTANT] Make sure there are at least ONE replica for each component If you want to scale in the last replica, may be you should consider to
STOPthe cluster.
Scale-in/out using Cluster API
Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.
spec:
terminationPolicy: Delete
componentSpecs:
- name: master
componentDef: elasticsearch-8
serviceVersion: 8.8.2
replicas: 3 # Update `replicas` to your need.
Vertical scaling
Vertical scaling involves increasing or decreasing resources to an existing database cluster. Resources that can be scaled include:, CPU cores/processing power and Memory (RAM).
To vertical scaling up or down specified component, you can apply the following yaml file:
# cat examples/elasticsearch/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: elasticsearch-verticalscaling
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: es-multinode
type: VerticalScaling
# Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
verticalScaling:
# Specifies the name of the Component.
# - master
# - data
# - ingest
# - transform
- componentName: master
# VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
requests:
cpu: '1'
memory: '3Gi'
limits:
cpu: '1'
memory: '3Gi'
kubectl apply -f examples/elasticsearch/verticalscale.yaml
Scale-up/down using Cluster API
Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.
spec:
terminationPolicy: Delete
componentSpecs:
- name: master
componentDef: elasticsearch-8
serviceVersion: 8.8.2
resources:
requests:
cpu: "1" # Update the resources to your need.
memory: "2Gi" # Update the resources to your need.
limits:
cpu: "2" # Update the resources to your need.
memory: "4Gi" # Update the resources to your need.
Expand volume
Volume expansion is the ability to increase the size of a Persistent Volume Claim (PVC) after it's created. It is introduced in Kubernetes v1.11 and goes GA in Kubernetes v1.24. It allows Kubernetes users to simply edit their PersistentVolumeClaim objects without requiring any downtime at all if possible.
[!NOTE] Make sure the storage class you use supports volume expansion.
Check the storage class with following command:
kubectl get storageclass
If the ALLOWVOLUMEEXPANSION column is true, the storage class supports volume expansion.
To increase size of volume storage with the specified components in the cluster
# cat examples/elasticsearch/volumeexpand.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: elasticsearch-volumeexpansion
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: es-multinode
type: VolumeExpansion
# Lists VolumeExpansion objects, each specifying a component and its corresponding volumeClaimTemplates that requires storage expansion.
volumeExpansion:
# Specifies the name of the Component.
# - master
# - data
# - ingest
# - transform
- componentName: data
# volumeClaimTemplates specifies the storage size and volumeClaimTemplate name.
volumeClaimTemplates:
# A reference to the volumeClaimTemplate name from the cluster components.
- name: data
storage: 30Gi
kubectl apply -f examples/elasticsearch/volumeexpand.yaml
After the operation, you will see the volume size of the specified component is increased to 30Gi in this case. Once you've done the change, check the status.conditions field of the PVC to see if the resize has completed.
Volume expansion using Cluster API
Alternatively, you may update the `spec.componentSpecs.volumeClaimTemplates.spec.resources.requests.sto
Deploy elasticsearch with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has elasticsearch on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartelasticsearch is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply