• This repository has been archived on 07/Nov/2018
  • Stars
    star
    1,510
  • Rank 31,048 (Top 0.7 %)
  • Language
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elasticsearch cluster on top of Kubernetes made easy.

This project is no longer maintained

As 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-cluster

Elasticsearch cluster on top of Kubernetes made easy.

Table of Contents

Abstract

Elasticsearch best-practices recommend to separate nodes in three roles:

  • Master nodes - intended for clustering management only, no data, no HTTP API
  • Data nodes - intended for client usage and data
  • Ingest nodes - intended for document pre-processing during ingestion

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

  • Elasticsearch pods need for an init-container to run in privileged mode, so it can set some VM options. For that to happen, the kubelet should be running with args --allow-privileged, otherwise the init-container will fail to run.

  • By default, ES_JAVA_OPTS is set to -Xms256m -Xmx256m. This is a very low value but many users, i.e. minikube users, were having issues with pods getting killed because hosts were out of memory. One can change this in the deployment descriptors available in this repository.

  • As of the moment, Kubernetes pod descriptors use an emptyDir for storing data in each data node container. This is meant to be for the sake of simplicity and should be adapted according to one's storage needs.

  • The stateful directory contains an example which deploys the data pods as a StatefulSet. These use a volumeClaimTemplates to provision persistent storage for each pod.

  • By default, PROCESSORS is set to 1. This may not be enough for some deployments, especially at startup time. Adjust resources.limits.cpu and/or livenessProbe accordingly if required. Note that resources.limits.cpu must be an integer.

Pre-requisites

  • Kubernetes 1.11.x (tested with v1.11.2 on top of Vagrant + CoreOS).
  • kubectl configured to access the Kubernetes API.

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.

Test

Deploy

kubectl 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 service

Don'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 kube-proxy or similar), run:

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-affinity

One 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:
  - (...)

Availability

If one wants to ensure that no more than n Elasticsearch nodes will be unavailable at a time, one can optionally (change and) apply the following manifests:

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 Helm

WARNING: 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 helm-elasticsearch/values.yaml file. For information about Helm, please consult the complete Helm documentation.

Install plug-ins

The image used in this repo is very minimalist. However, one can install additional plug-ins at will by simply specifying the ES_PLUGINS_INSTALL environment variable in the desired pod descriptors. For instance, to install Google Cloud Storage and S3 plug-ins it would be like follows:

- name: "ES_PLUGINS_INSTALL"
  value: "repository-gcs,repository-s3"

Note: The X-Pack plugin does not currently work with the quay.io/pires/docker-elasticsearch-kubernetes image. See Issue #102

Clean-up with Curator

Additionally, 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

  • One can change the schedule by editing the cron notation in es-curator.yaml.
  • One can change the action (e.g. delete older than 3 days) by editing the es-curator-config.yaml.
  • The definition of the action_file.yaml is quite self-explaining for simple set-ups. For more advanced configuration options, please consult the Curator Documentation.

If one wants to remove the curator job, just run:

kubectl delete cronjob curator
kubectl delete configmap curator-config

Kibana

WARNING: The Kibana section is maintained by someone else in the community and may not up-to-date with this repo.

Deploy

If Kibana defaults are not enough, one may want to customize kibana.yaml through a ConfigMap. Please refer to Configuring Kibana for all available attributes.

kubectl create -f kibana-cm.yaml
kubectl create -f kibana-svc.yaml
kubectl create -f kibana.yaml

Kibana will become available through service kibana, and one will be able to access it from within the cluster, or proxy it through the Kubernetes API as follows:

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 SERVER_BASEPATH to the match their environment.

FAQ

Why does NUMBER_OF_MASTERS differ from number of master-replicas?

The default value for this environment variable is 2, meaning a cluster will need a minimum of 2 master nodes to operate. If a cluster has 3 masters and one dies, the cluster still works. Minimum master nodes are usually n/2 + 1, where n is the number of master nodes in a cluster. If a cluster has 5 master nodes, one should have a minimum of 3, less than that and the cluster stops. If one scales the number of masters, make sure to update the minimum number of master nodes through the Elasticsearch API as setting environment variable will only work on cluster setup. More info: https://www.elastic.co/guide/en/elasticsearch/guide/1.x/_important_configuration_changes.html#_minimum_master_nodes

How can I customize elasticsearch.yaml?

Read a different config file by settings env var ES_PATH_CONF=/path/to/my/config/ (see the Elasticsearch docs for more). Another option would be to build one's own image from this repository

Troubleshooting

No up-and-running site-local

One of the errors one may come across when running the setup is the following error:

[2016-11-29T01:28:36,515][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: No up-and-running site-local (private) addresses found, got [name:lo (lo), name:eth0 (eth0)]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:116) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.cli.Command.main(Command.java:62) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:73) ~[elasticsearch-5.0.1.jar:5.0.1]
Caused by: java.lang.IllegalArgumentException: No up-and-running site-local (private) addresses found, got [name:lo (lo), name:eth0 (eth0)]
	at org.elasticsearch.common.network.NetworkUtils.getSiteLocalAddresses(NetworkUtils.java:187) ~[elasticsearch-5.0.1.jar:5.0.1]
	at org.elasticsearch.common.network.NetworkService.resolveInternal(NetworkService.java:246) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.common.network.NetworkService.resolveInetAddresses(NetworkService.java:220) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.common.network.NetworkService.resolveBindHostAddresses(NetworkService.java:130) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.transport.TcpTransport.bindServer(TcpTransport.java:575) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:182) ~[?:?]
 	at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.transport.TransportService.doStart(TransportService.java:182) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.node.Node.start(Node.java:525) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:211) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:288) ~[elasticsearch-5.0.1.jar:5.0.1]
 	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:112) ~[elasticsearch-5.0.1.jar:5.0.1]
 	... 6 more
[2016-11-29T01:28:37,448][INFO ][o.e.n.Node               ] [kIEYQSE] stopping ...
[2016-11-29T01:28:37,451][INFO ][o.e.n.Node               ] [kIEYQSE] stopped
[2016-11-29T01:28:37,452][INFO ][o.e.n.Node               ] [kIEYQSE] closing ...
[2016-11-29T01:28:37,464][INFO ][o.e.n.Node               ] [kIEYQSE] closed

This is related to how the container binds to network ports (defaults to _local_). It will need to match the actual node network interface name, which depends on what OS and infrastructure provider one uses. For instance, if the primary interface on the node is p1p1 then that is the value that needs to be set for the NETWORK_HOST environment variable. Please see the documentation for reference of options.

In order to workaround this, set NETWORK_HOST environment variable in the pod descriptors as follows:

- name: "NETWORK_HOST"
  value: "_eth0_" #_p1p1_ if interface name is p1p1, _ens4_ if interface name is ens4, and so on.

(IPv6) org.elasticsearch.bootstrap.StartupException: BindTransportException

Intermittent failures occur when the local network interface has both IPv4 and IPv6 addresses, and Elasticsearch tries to bind to the IPv6 address first. If the IPv4 address is chosen first, Elasticsearch starts correctly.

In order to workaround this, set NETWORK_HOST environment variable in the pod descriptors as follows:

- name: "NETWORK_HOST"
  value: "_eth0:ipv4_" #_p1p1:ipv4_ if interface name is p1p1, _ens4:ipv4_ if interface name is ens4, and so on.

More Repositories

1

android-obd-reader

Android OBD-II Reader application that uses pure OBD-II PID's Java API.
Java
808
star
2

kubernetes-vagrant-coreos-cluster

Kubernetes cluster (for testing purposes) made easy with Vagrant and CoreOS.
Shell
597
star
3

obd-java-api

OBD-II Java API
Java
597
star
4

go-proxyproto

A Go library implementation of the PROXY protocol, versions 1 and 2.
Go
488
star
5

docker-elasticsearch-kubernetes

Ready to use Elasticsearch + Kubernetes discovery plug-in Docker image.
Dockerfile
224
star
6

kubernetes-nats-cluster

NATS cluster on top of Kubernetes made easy.
Go
168
star
7

docker-elasticsearch

Dockerfile for a base Elasticsearch image to be extended by others (allow to install plug-ins, change configuration, etc.)
Shell
161
star
8

kubernetes-elk-cluster

ELK (Elasticsearch + Logstash + Kibana) cluster on top of Kubernetes made easy.
Dockerfile
148
star
9

spring-boot-shiro-orientdb

A simple REST API built with Spring Boot and OrientDB (Object API) datastore, secured with Apache Shiro (distributed session storage powered by Hazelcast).
Java
98
star
10

obd-server

Webapp responsible for storing OBD (Android OBD Reader) readings.
Java
69
star
11

hibernate-postgres-jsonb

A working implementation of JSONB support on a Java + Hibernate application.
Java
63
star
12

hazelcast-kubernetes

Hazelcast clustering for Kubernetes made easy.
Dockerfile
49
star
13

simple-shiro-web-app

A simple proof-of-concept of Shiro authentication with JDBC Realm and MySQL.
CSS
36
star
14

nomad-vagrant-coreos-cluster

Nomad cluster (for testing purposes) made easy with Vagrant and CoreOS.
Shell
35
star
15

docker-jre

Lean JRE 8 Docker container
Dockerfile
24
star
16

hazelcast-kubernetes-bootstrapper

Hazelcast cluster discovery mechanism for Kubernetes.
Java
22
star
17

rethinkdb-coreos-cluster

RethinkDB clustering made easy with CoreOS, etcd2 and Docker
Shell
21
star
18

netty-tcnative-alpine

Build netty-tcnative native binaries for Alpine Linux.
Dockerfile
20
star
19

kubernetes-squid

Squid proxy for Kubernetes
15
star
20

apache-ignite-discovery-kubernetes

Apache Ignite discovery for Kubernetes.
Java
10
star
21

nats-coreos-cluster

NATS clustering made easy with CoreOS and etcd.
Shell
10
star
22

docker-logstash

Dockerfile for a base Logstash image to be extended by others (allow to install plug-ins, change configuration, etc.)
10
star
23

nats-sniffer

A simple sniffer for NATS, the cloud native messaging system. https://nats.io
Go
10
star
24

consul-lb-gce

A smart Google Cloud Engine load-balancer manager for Consul backed services.
Go
10
star
25

simple-jersey-rest-app

A simple proof-of-concept of RESTful web service implemented with Jersey and Glassfish.
Java
10
star
26

alpine-linux-build

Docker image of Alpine Linux with many compilers needed to build code that's meant to run on Alpine Linux.
9
star
27

fabric8-persistence-hibernate

Fabric8 + E-OSGi JPA 2.1 managed persistence (Aries + Hibernate 4.3.x) + REST service demonstration code.
Java
9
star
28

docker-elasticsearch-aws

Ready to use Elasticsearch + AWS plug-in Docker image.
Dockerfile
9
star
29

simple-jpa-hibernate-guice-desktop-app

A simple proof-of-concept of a desktop Java application with database access using JPA, Hibernate and Guice.
Java
9
star
30

fabric8-cxf-shiro

OSGi-enabled authentication & authorization service, powered by Apache Shiro and Hazelcast cluster. Goes really well with Fabric8 or JBoss Fuse for auto-scaling.
Java
8
star
31

docker-haproxy-ssl

5
star
32

docker-apache-ignite

Lean (310MB) Apache Ignite docker image.
5
star
33

docker-hbase-standalone

Simple HBase standalone container image.
4
star
34

pgskail

PostgreSQL high-availability made easy.
Go
4
star
35

docker-logstash-forwarder

logstash-forwarder minimal Docker container image
Shell
4
star
36

docker-elasticsearch-curator

Lean Elasticsearch Curator container image, based on Alpine Linux 3.7 and Python 3.
Dockerfile
4
star
37

docker-squid

Run Squid on a Docker container. The main purpose of this it to use it as Docker registry cache.
Shell
4
star
38

docker-apollomq

Docker image for Apache ActiveMQ Apollo broker.
3
star
39

dojo-go-consul

A repo for my experiments with Consul and Go.
Go
3
star
40

go-dojo-scalability-protocols

Go experiment with [Scalability Protocols](http://bravenewgeek.com/a-look-at-nanomsg-and-scalability-protocols/).
Go
3
star
41

sherlock

Message-driven, NoSQL-powered auditing framework
Java
3
star
42

fabric8-cxf-dosgi-demo-blueprint

Simple Fabric8-oriented CXF + DOSGi demonstration code.
Java
2
star
43

springboot-stomp-ws-jms-integration

Example of integration between two apps and one frontend with STOMP over WebSocket and JMS.
JavaScript
2
star
44

configo

TOML-based, strong-typed, environment-oriented, a la fullstack configuration for Go applications.
Go
2
star
45

kubernetes-operator-dev

Dockerfile
2
star
46

go-dojo-rectangles

Go experiments with rectangles.
Go
2
star
47

fabric8-amq-example

Fabric8 ActiveMQ (JMS) example with Pax-Exam integration-tests
Java
2
star
48

opensignals-android

BITalino OpenSignals application for Android plattform.
Java
2
star
49

netty-socketio-osgi-example

Netty-SocketIO OSGi example
Java
2
star
50

replicatorg-mavenized

Mavenized version of ReplicatorG project
Java
1
star
51

metricas

A pipeline for metrics acquisition and storage.
Go
1
star
52

simple-hibernate-kundera-cassandra-polyglot-app

Simple polyglot proof-of-concept with Hibernate (PostgreSQL) and Kundera (Cassandra) support.
Java
1
star
53

fabric8-osgi-aspectj

Fabric8 example with OSGi and AspectJ (AOP) aspects woven in compile-time.
Java
1
star
54

simple-kundera-embedded-cassandra-app

A simple proof-of-concept of a Java application with embedded Cassandra integration, using Kundera and Guice.
Java
1
star