开源软件名称(OpenSource Name):pires/kubernetes-elasticsearch-cluster开源软件地址(OpenSource Url):https://github.com/pires/kubernetes-elasticsearch-cluster开源编程语言(OpenSource Language):开源软件介绍(OpenSource Introduction):This project is no longer maintainedAs of November 7th, 2018, I've decided to end my commitment to maintaining this repo and related. It's been 3 years since I last used Elasticsearch, so I no longer have the motivation it takes to maintain and evolve this project. Also, other projects need all the attention I can give. It was a great run, thank you all. kubernetes-elasticsearch-clusterElasticsearch cluster on top of Kubernetes made easy. Table of Contents
AbstractElasticsearch best-practices recommend to separate nodes in three roles:
Given this, I'm going to demonstrate how to provision a production grade scenario consisting of 3 master, 2 data and 2 ingest nodes. (Very) Important notes
Pre-requisites
Build images (optional)Providing one's own version of the images automatically built from this repository will not be supported. This is an optional step. One has been warned. TestDeploykubectl create -f es-discovery-svc.yaml
kubectl create -f es-svc.yaml
kubectl create -f es-master.yaml
kubectl rollout status -f es-master.yaml
kubectl create -f es-ingest-svc.yaml
kubectl create -f es-ingest.yaml
kubectl rollout status -f es-ingest.yaml
kubectl create -f es-data.yaml
kubectl rollout status -f es-data.yaml Let's check if everything is working properly: kubectl get svc,deployment,pods -l component=elasticsearch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/elasticsearch ClusterIP 10.100.243.196 <none> 9200/TCP 3m
service/elasticsearch-discovery ClusterIP None <none> 9300/TCP 3m
service/elasticsearch-ingest ClusterIP 10.100.76.74 <none> 9200/TCP 2m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.extensions/es-data 2 2 2 2 1m
deployment.extensions/es-ingest 2 2 2 2 2m
deployment.extensions/es-master 3 3 3 3 3m
NAME READY STATUS RESTARTS AGE
pod/es-data-56f8ff8c97-642bq 1/1 Running 0 1m
pod/es-data-56f8ff8c97-h6hpc 1/1 Running 0 1m
pod/es-ingest-6ddd5fc689-b4s94 1/1 Running 0 2m
pod/es-ingest-6ddd5fc689-d8rtj 1/1 Running 0 2m
pod/es-master-68bf8f86c4-bsfrx 1/1 Running 0 3m
pod/es-master-68bf8f86c4-g8nph 1/1 Running 0 3m
pod/es-master-68bf8f86c4-q5khn 1/1 Running 0 3m As we can assert, the cluster seems to be up and running. Easy, wasn't it? Access the serviceDon't forget that services in Kubernetes are only acessible from containers in the cluster. For different behavior one should configure the creation of an external load-balancer. While it's supported within this example service descriptor, its usage is out of scope of this document, for now. Note: if you are using one of the cloud providers which support external load balancers, setting the type field to "LoadBalancer" will provision a load balancer for your Service. You can uncomment the field in es-svc.yaml. kubectl get svc elasticsearch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch ClusterIP 10.100.243.196 <none> 9200/TCP 3m From any host on the Kubernetes cluster (that's running curl http://10.100.243.196:9200 One should see something similar to the following: {
"name" : "es-data-56f8ff8c97-642bq",
"cluster_name" : "myesdb",
"cluster_uuid" : "RkRkTl26TDOE7o0FhCcW_g",
"version" : {
"number" : "6.3.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "053779d",
"build_date" : "2018-07-20T05:20:23.451332Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
} Or if one wants to see cluster information: curl http://10.100.243.196:9200/_cluster/health?pretty One should see something similar to the following: {
"cluster_name" : "myesdb",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 7,
"number_of_data_nodes" : 2,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
} Pod anti-affinityOne of the main advantages of running Elasticsearch on top of Kubernetes is how resilient the cluster becomes, particularly during node restarts. However if all data pods are scheduled onto the same node(s), this advantage decreases significantly and may even result in no data pods being available. It is then highly recommended, in the context of the solution described in this repository, that one adopts pod anti-affinity in order to guarantee that two data pods will never run on the same node. Here's an example: spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- elasticsearch
- key: role
operator: In
values:
- data
topologyKey: kubernetes.io/hostname
containers:
- (...) AvailabilityIf one wants to ensure that no more than kubectl create -f es-master-pdb.yaml
kubectl create -f es-data-pdb.yaml Note: This is an advanced subject and one should only put it in practice if one understands clearly what it means both in the Kubernetes and Elasticsearch contexts. For more information, please consult Pod Disruptions. Deploy with HelmWARNING: The Helm chart is maintained by someone else in the community and may not up-to-date with this repo. Helm charts for a basic (non-stateful) ElasticSearch deployment are maintained at https://github.com/clockworksoul/helm-elasticsearch. With Helm properly installed and configured, standing up a complete cluster is almost trivial: git clone https://github.com/clockworksoul/helm-elasticsearch.git
helm install helm-elasticsearch Various parameters of the cluster, including replica count and memory allocations, can be adjusted by editing the Install plug-insThe image used in this repo is very minimalist. However, one can install additional plug-ins at will by simply specifying the - name: "ES_PLUGINS_INSTALL"
value: "repository-gcs,repository-s3" Note: The X-Pack plugin does not currently work with the Clean-up with CuratorAdditionally, one can run a CronJob that will periodically run Curator to clean up indices (or do other actions on the Elasticsearch cluster). kubectl create -f es-curator-config.yaml
kubectl create -f es-curator.yaml Please, confirm the job has been created. kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST-SCHEDULE
curator 1 0 * * * False 0 <none> The job is configured to run once a day at 1 minute past midnight and delete indices that are older than 3 days. Notes
If one wants to remove the curator job, just run: kubectl delete cronjob curator
kubectl delete configmap curator-config KibanaWARNING: The Kibana section is maintained by someone else in the community and may not up-to-date with this repo. DeployIf Kibana defaults are not enough, one may want to customize kubectl create -f kibana-cm.yaml
kubectl create -f kibana-svc.yaml
kubectl create -f kibana.yaml Kibana will become available through service curl https://<API_SERVER_URL>/api/v1/namespaces/default/services/kibana:http/proxy One can also create an Ingress to expose the service publicly or simply use the service nodeport.
In the case one proceeds to do so, one must change the environment variable FAQ
Why does |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论