github.com/qsunny/k8s@v0.0.0-20220101153623-e6dca256d5bf/examples-master/staging/elasticsearch/README.md (about) 1 # Elasticsearch for Kubernetes 2 3 Kubernetes makes it trivial for anyone to easily build and scale [Elasticsearch](http://www.elasticsearch.org/) clusters. Here, you'll find how to do so. 4 Current Elasticsearch version is `5.6.2`. 5 6 [A more robust example that follows Elasticsearch best-practices of separating nodes concern is also available](production_cluster/README.md). 7 8 Current 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 your storage needs](https://kubernetes.io/docs/concepts/storage/persistent-volumes/). 9 10 ## Docker image 11 12 The [pre-built image](https://github.com/pires/docker-elasticsearch-kubernetes) used in this example will not be supported. Feel free to fork to fit your own needs, but keep in mind that you will need to change Kubernetes descriptors accordingly. 13 14 ## Deploy 15 16 Let's kickstart our cluster with 1 instance of Elasticsearch. 17 18 ``` 19 kubectl create -f staging/elasticsearch/service-account.yaml 20 kubectl create -f staging/elasticsearch/es-svc.yaml 21 kubectl create -f staging/elasticsearch/es-rc.yaml 22 ``` 23 24 The [io.fabric8:elasticsearch-cloud-kubernetes](https://github.com/fabric8io/elasticsearch-cloud-kubernetes) plugin requires limited access to the Kubernetes API in order to fetch the list of Elasticsearch endpoints. 25 If your cluster has the RBAC authorization mode enabled, create the additional `Role` and `RoleBinding` with: 26 27 ``` 28 kubectl create -f staging/elasticsearch/rbac.yaml 29 ``` 30 31 Let's see if it worked: 32 33 ``` 34 $ kubectl get pods 35 NAME READY STATUS RESTARTS AGE 36 es-q8q2v 1/1 Running 0 2m 37 ``` 38 39 ``` 40 $ kubectl logs es-q8q2v 41 [2017-10-02T11:39:22,347][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] initializing ... 42 [2017-10-02T11:39:22,579][INFO ][o.e.e.NodeEnvironment ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] using [1] data paths, mounts [[/data (/dev/sda1)]], net usable_space [92.5gb], net total_space [94.3gb], spins? [possibly], types [ext4] 43 [2017-10-02T11:39:22,579][INFO ][o.e.e.NodeEnvironment ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] heap size [503.6mb], compressed ordinary object pointers [true] 44 [2017-10-02T11:39:22,581][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] node name [ece3d296-dbd3-46a3-b66c-8b4c282610af], node ID [Rc-odsaESxSAnvOBFg4MNA] 45 [2017-10-02T11:39:22,582][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] version[5.6.2], pid[9], build[57e20f3/2017-09-23T13:16:45.703Z], OS[Linux/4.4.64+/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_131/25.131-b11] 46 [2017-10-02T11:39:22,583][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] JVM arguments [-XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Xms512m, -Xmx512m, -Des.path.home=/elasticsearch] 47 [2017-10-02T11:39:24,386][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [aggs-matrix-stats] 48 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [ingest-common] 49 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-expression] 50 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-groovy] 51 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-mustache] 52 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-painless] 53 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [parent-join] 54 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [percolator] 55 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [reindex] 56 [2017-10-02T11:39:24,389][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [transport-netty3] 57 [2017-10-02T11:39:24,389][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [transport-netty4] 58 [2017-10-02T11:39:24,389][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] no plugins loaded 59 [2017-10-02T11:39:27,395][INFO ][o.e.d.DiscoveryModule ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] using discovery type [zen] 60 [2017-10-02T11:39:28,754][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] initialized 61 [2017-10-02T11:39:28,758][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] starting ... 62 [2017-10-02T11:39:29,132][INFO ][o.e.t.TransportService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] publish_address {10.44.2.5:9300}, bound_addresses {10.44.2.5:9300} 63 [2017-10-02T11:39:29,154][INFO ][o.e.b.BootstrapChecks ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks 64 [2017-10-02T11:39:32,264][INFO ][o.e.c.s.ClusterService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] new_master {ece3d296-dbd3-46a3-b66c-8b4c282610af}{Rc-odsaESxSAnvOBFg4MNA}{YvzOdsplT12C-9c7X3O8Xw}{10.44.2.5}{10.44.2.5:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) 65 [2017-10-02T11:39:32,315][INFO ][o.e.h.n.Netty4HttpServerTransport] [ece3d296-dbd3-46a3-b66c-8b4c282610af] publish_address {10.44.2.5:9200}, bound_addresses {10.44.2.5:9200} 66 [2017-10-02T11:39:32,316][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] started 67 [2017-10-02T11:39:32,331][INFO ][o.e.g.GatewayService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] recovered [0] indices into cluster_state 68 ``` 69 70 So we have a 1-node Elasticsearch cluster ready to handle some work. 71 72 ## Scale 73 74 Scaling is as easy as: 75 76 ``` 77 kubectl scale --replicas=3 rc es 78 ``` 79 80 Did it work? 81 82 ``` 83 $ kubectl get pods 84 NAME READY STATUS RESTARTS AGE 85 es-95h78 1/1 Running 0 3m 86 es-q8q2v 1/1 Running 0 6m 87 es-qdcnd 1/1 Running 0 3m 88 ``` 89 90 Let's take a look at logs: 91 92 ``` 93 $ kubectl logs es-q8q2v 94 [2017-10-02T11:39:22,347][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] initializing ... 95 [2017-10-02T11:39:22,579][INFO ][o.e.e.NodeEnvironment ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] using [1] data paths, mounts [[/data (/dev/sda1)]], net usable_space [92.5gb], net total_space [94.3gb], spins? [possibly], types [ext4] 96 [2017-10-02T11:39:22,579][INFO ][o.e.e.NodeEnvironment ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] heap size [503.6mb], compressed ordinary object pointers [true] 97 [2017-10-02T11:39:22,581][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] node name [ece3d296-dbd3-46a3-b66c-8b4c282610af], node ID [Rc-odsaESxSAnvOBFg4MNA] 98 [2017-10-02T11:39:22,582][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] version[5.6.2], pid[9], build[57e20f3/2017-09-23T13:16:45.703Z], OS[Linux/4.4.64+/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_131/25.131-b11] 99 [2017-10-02T11:39:22,583][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] JVM arguments [-XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Xms512m, -Xmx512m, -Des.path.home=/elasticsearch] 100 [2017-10-02T11:39:24,386][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [aggs-matrix-stats] 101 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [ingest-common] 102 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-expression] 103 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-groovy] 104 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-mustache] 105 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [lang-painless] 106 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [parent-join] 107 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [percolator] 108 [2017-10-02T11:39:24,388][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [reindex] 109 [2017-10-02T11:39:24,389][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [transport-netty3] 110 [2017-10-02T11:39:24,389][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] loaded module [transport-netty4] 111 [2017-10-02T11:39:24,389][INFO ][o.e.p.PluginsService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] no plugins loaded 112 [2017-10-02T11:39:27,395][INFO ][o.e.d.DiscoveryModule ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] using discovery type [zen] 113 [2017-10-02T11:39:28,754][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] initialized 114 [2017-10-02T11:39:28,758][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] starting ... 115 [2017-10-02T11:39:29,132][INFO ][o.e.t.TransportService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] publish_address {10.44.2.5:9300}, bound_addresses {10.44.2.5:9300} 116 [2017-10-02T11:39:29,154][INFO ][o.e.b.BootstrapChecks ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks 117 [2017-10-02T11:39:32,264][INFO ][o.e.c.s.ClusterService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] new_master {ece3d296-dbd3-46a3-b66c-8b4c282610af}{Rc-odsaESxSAnvOBFg4MNA}{YvzOdsplT12C-9c7X3O8Xw}{10.44.2.5}{10.44.2.5:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) 118 [2017-10-02T11:39:32,315][INFO ][o.e.h.n.Netty4HttpServerTransport] [ece3d296-dbd3-46a3-b66c-8b4c282610af] publish_address {10.44.2.5:9200}, bound_addresses {10.44.2.5:9200} 119 [2017-10-02T11:39:32,316][INFO ][o.e.n.Node ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] started 120 [2017-10-02T11:39:32,331][INFO ][o.e.g.GatewayService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] recovered [0] indices into cluster_state 121 [2017-10-02T11:42:39,410][INFO ][o.e.c.s.ClusterService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] added {{8bcf8744-c48a-4ebb-86d8-e677a61141b7}{nFExy7_bS--Vcd42xrnFrw}{RQyzD2UnR--UUEfyfPuHgg}{10.44.0.5}{10.44.0.5:9300},}, reason: zen-disco-node-join[{8bcf8744-c48a-4ebb-86d8-e677a61141b7}{nFExy7_bS--Vcd42xrnFrw}{RQyzD2UnR--UUEfyfPuHgg}{10.44.0.5}{10.44.0.5:9300}] 122 [2017-10-02T11:42:39,470][WARN ][o.e.d.z.ElectMasterService] [ece3d296-dbd3-46a3-b66c-8b4c282610af] value for setting "discovery.zen.minimum_master_nodes" is too low. This can result in data loss! Please set it to at least a quorum of master-eligible nodes (current value: [1], total number of master-eligible nodes used for publishing in this round: [2]) 123 [2017-10-02T11:42:42,586][INFO ][o.e.c.s.ClusterService ] [ece3d296-dbd3-46a3-b66c-8b4c282610af] added {{3b2f3585-7706-416d-bede-c467a46ab30f}{eG6p9sJRQ9yShS97yL3pQg}{JqGe38AeSKmHQfLaICibQA}{10.44.1.5}{10.44.1.5:9300},}, reason: zen-disco-node-join[{3b2f3585-7706-416d-bede-c467a46ab30f}{eG6p9sJRQ9yShS97yL3pQg}{JqGe38AeSKmHQfLaICibQA}{10.44.1.5}{10.44.1.5:9300}] 124 ``` 125 126 So we have a 3-node Elasticsearch cluster ready to handle more work. 127 128 ## Access the service 129 130 *Don't forget* that services in Kubernetes are only acessible from containers in the cluster. For different behavior you should [configure the creation of an external load-balancer](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer). While it's supported within this example service descriptor, its usage is out of scope of this document, for now. 131 132 ``` 133 $ kubectl get service elasticsearch 134 NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE 135 elasticsearch 10.47.252.248 35.200.115.240 9200:31394/TCP,9300:30907/TCP 6m 136 ``` 137 138 From any host on your cluster (that's running `kube-proxy`), run: 139 140 ``` 141 $ curl 35.200.115.240:9200 142 ``` 143 144 You should see something similar to the following: 145 146 147 ```json 148 { 149 "name" : "ece3d296-dbd3-46a3-b66c-8b4c282610af", 150 "cluster_name" : "myesdb", 151 "cluster_uuid" : "lb76DGaGS1msgwC3w8H9Qg", 152 "version" : { 153 "number" : "5.6.2", 154 "build_hash" : "57e20f3", 155 "build_date" : "2017-09-23T13:16:45.703Z", 156 "build_snapshot" : false, 157 "lucene_version" : "6.6.1" 158 }, 159 "tagline" : "You Know, for Search" 160 } 161 ``` 162 163 Or if you want to check cluster information: 164 165 166 ``` 167 curl 35.189.128.215:9200/_cluster/health?pretty 168 ``` 169 170 You should see something similar to the following: 171 172 ```json 173 { 174 "cluster_name" : "myesdb", 175 "status" : "green", 176 "timed_out" : false, 177 "number_of_nodes" : 3, 178 "number_of_data_nodes" : 3, 179 "active_primary_shards" : 0, 180 "active_shards" : 0, 181 "relocating_shards" : 0, 182 "initializing_shards" : 0, 183 "unassigned_shards" : 0, 184 "delayed_unassigned_shards" : 0, 185 "number_of_pending_tasks" : 0, 186 "number_of_in_flight_fetch" : 0, 187 "task_max_waiting_in_queue_millis" : 0, 188 "active_shards_percent_as_number" : 100.0 189 } 190 ``` 191 192 <!-- BEGIN MUNGE: GENERATED_ANALYTICS --> 193 []() 194 <!-- END MUNGE: GENERATED_ANALYTICS -->