To deploy an Elasticsearch cluster in Kubernetes after you have the Elastic Operator already deployed, you will need to create an Elasticsearch custom resource definition (CRD). The Elastic Operator will watch for instances of this CRD and create the necessary Kubernetes resources to deploy the Elasticsearch cluster accordingly.
-
Prepare the Elasticsearch Cluster Configuration:
Define your Elasticsearch cluster configuration in a .yaml file. For example, create a file named elasticsearch-cluster.yaml with content similar to the following:
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: elasticsearch-sample
spec:
version: "7.10.0" # specify the version of Elasticsearch you want to deploy
nodeSets:
- name: default
count: 3
config:
node.store.allow_mmap: false
Adjust the version, count, and other configurations to match your desired cluster setup.
-
Apply the Elasticsearch Configuration:
Use kubectl to apply the configuration file created in step 1:
kubectl apply -f elasticsearch-cluster.yaml
-
Check the Status of the Elasticsearch Cluster:
You can check the status of your cluster using the following command:
kubectl get elasticsearch
To get more detailed information, you can describe a particular cluster:
kubectl describe elasticsearch elasticsearch-sample
-
Access the Elasticsearch Cluster:
Depending on how you configured the service, you might need to either port-forward the service to your local machine or set up an Ingress or LoadBalancer service to access it externally.
For port-forwarding, you can use:
kubectl port-forward service/elasticsearch-sample-es-http 9200
Now you can access the Elasticsearch API at http://localhost:9200.
-
Set up Authentication (if necessary):
Elastic Operator manages the security of the Elasticsearch cluster by default. Check the generated credentials to access your cluster:
kubectl get secret elasticsearch-sample-es-elastic-user -o=jsonpath='{.data.elastic}' | base64 --decode; echo
-
Scale the Elasticsearch Cluster:
If you need to scale your cluster up or down, you can modify the count field in the nodeSets section of your elasticsearch-cluster.yaml file and apply the changes using kubectl apply.
-
Monitor the Elasticsearch Cluster:
Keep an eye on the pods and resources created by the Elasticsearch cluster:
kubectl get pods,svc,pvc -l 'elasticsearch.k8s.elastic.co/cluster-name=elasticsearch-sample'
This will show you the pods, services, and persistent volume claims associated with your Elasticsearch cluster.
-
Upgrade the Elasticsearch Cluster:
When it's time to upgrade your cluster, you can change the spec.version in the elasticsearch-cluster.yaml file to the desired version and apply the changes. The Elastic Operator will handle the rolling upgrade process.
Remember to consult the official ECK (Elastic Cloud on Kubernetes) documentation for the specific version of the Elastic Operator you have installed to ensure that you're following any updated procedures or configurations. The Elastic Operator simplifies many of the operational complexities in running Elasticsearch, but it's still important to understand the underlying concepts and configurations that make your cluster function according to your needs.