Skip to content

Commit

Permalink
[elasticsearch] use new node.roles settings (elastic#1186)
Browse files Browse the repository at this point in the history
* [elasticsearch] use new node.roles settings

This commit update Elasticsearch chart to use the new node.roles
settings introduced in elastic/elasticsearch#54998.

* [elasticsearch] update doc

* [elasticsearch] update examples

* add link to roles doc

* add workaround for coordinating node

* update roles list

* fixup! update roles list

* remove data_frozen from default roles

this is needed because `data_frozen` role doesn't exist in Elasticsearch < 7.12.0

* fixup! remove data_frozen from default roles
  • Loading branch information
jmlrt authored May 25, 2021
1 parent 8ddb15b commit 0626843
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 73 deletions.
26 changes: 23 additions & 3 deletions elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ support multiple versions with minimal changes.
| `readinessProbe` | Configuration fields for the readiness [probe][] | see [values.yaml][] |
| `replicas` | Kubernetes replica count for the StatefulSet (i.e. how many pods) | `3` |
| `resources` | Allows you to set the [resources][] for the StatefulSet | see [values.yaml][] |
| `roles` | A hash map with the specific [roles][] for the `nodeGroup` | see [values.yaml][] |
| `roles` | A list with the specific [roles][] for the `nodeGroup` | see [values.yaml][] |
| `schedulerName` | Name of the [alternate scheduler][] | `""` |
| `secretMounts` | Allows you easily mount a secret as a file inside the StatefulSet. Useful for mounting certificates and other secrets. See [values.yaml][] for an example | `[]` |
| `securityContext` | Allows you to set the [securityContext][] for the container | see [values.yaml][] |
Expand Down Expand Up @@ -212,8 +212,27 @@ while they share the same `clusterName` value.

For each Helm release, the nodes types can then be defined using `roles` value.

An example of Elasticsearch cluster using 2 different Helm releases for master
and data nodes can be found in [examples/multi][].
An example of Elasticsearch cluster using 2 different Helm releases for master,
data and coordinating nodes can be found in [examples/multi][].

#### Coordinating nodes

Every node is implicitly a coordinating node. This means that a node that has an
explicit empty list of roles will only act as a coordinating node.

When deploying coordinating-only node with Elasticsearch chart, it is required
to define the empty list of roles in both `roles` value and `node.roles`
settings:

```yaml
roles: []

esConfig:
elasticsearch.yml: |
node.roles: []
```
More details in [#1186 (comment)][]
#### Clustering and Node Discovery
Expand Down Expand Up @@ -380,6 +399,7 @@ about our development and testing process.

[7.x]: https://github.com/elastic/helm-charts/releases
[#63]: https://github.com/elastic/helm-charts/issues/63
[#1186 (comment)]: https://github.com/elastic/helm-charts/pull/1186#discussion_r631166442
[7.9.2]: https://github.com/elastic/helm-charts/blob/7.9.2/elasticsearch/README.md
[BREAKING_CHANGES.md]: https://github.com/elastic/helm-charts/blob/master/BREAKING_CHANGES.md
[CHANGELOG.md]: https://github.com/elastic/helm-charts/blob/master/CHANGELOG.md
Expand Down
8 changes: 2 additions & 6 deletions elasticsearch/examples/migration/client.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
---

replicas: 2

clusterName: "elasticsearch"
nodeGroup: "client"

esMajorVersion: 6

roles:
master: "false"
ingest: "false"
data: "false"
roles: []

volumeClaimTemplate:
accessModes: [ "ReadWriteOnce" ]
accessModes: ["ReadWriteOnce"]
storageClassName: "standard"
resources:
requests:
Expand Down
5 changes: 1 addition & 4 deletions elasticsearch/examples/migration/data.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

replicas: 2

esMajorVersion: 6
Expand All @@ -12,6 +11,4 @@ clusterName: "elasticsearch"
nodeGroup: "data"

roles:
master: "false"
ingest: "false"
data: "true"
- data
7 changes: 2 additions & 5 deletions elasticsearch/examples/migration/master.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

# Temporarily set to 3 so we can scale up/down the old a new cluster
# one at a time whilst always keeping 3 masters running
replicas: 1
Expand All @@ -14,12 +13,10 @@ clusterName: "elasticsearch"
nodeGroup: "master"

roles:
master: "true"
ingest: "false"
data: "false"
- master

volumeClaimTemplate:
accessModes: [ "ReadWriteOnce" ]
accessModes: ["ReadWriteOnce"]
storageClassName: "standard"
resources:
requests:
Expand Down
14 changes: 7 additions & 7 deletions elasticsearch/examples/multi/client.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---

clusterName: "multi"
nodeGroup: "client"

roles:
master: "false"
ingest: "false"
data: "false"
ml: "false"
remote_cluster_client: "false"
roles: []

persistence:
enabled: false

# For client nodes, we also need to add an empty node.roles in elasticsearch.yml
# This is due to https://github.com/elastic/helm-charts/pull/1186#discussion_r631225687
esConfig:
elasticsearch.yml: |
node.roles: []
13 changes: 7 additions & 6 deletions elasticsearch/examples/multi/data.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---

clusterName: "multi"
nodeGroup: "data"

roles:
master: "false"
ingest: "true"
data: "true"
ml: "false"
remote_cluster_client: "false"
- data
- data_content
- data_hot
- data_warm
- data_cold
- data_frozen
- ingest
7 changes: 1 addition & 6 deletions elasticsearch/examples/multi/master.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
---

clusterName: "multi"
nodeGroup: "master"

roles:
master: "true"
ingest: "false"
data: "false"
ml: "false"
remote_cluster_client: "false"
- master
6 changes: 3 additions & 3 deletions elasticsearch/examples/security/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ clusterName: "security"
nodeGroup: "master"

roles:
master: "true"
ingest: "true"
data: "true"
- master
- ingest
- data

protocol: https

Expand Down
6 changes: 6 additions & 0 deletions elasticsearch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- end -}}
{{- end -}}

{{- define "elasticsearch.roles" -}}
{{- range $.Values.roles -}}
{{ . }},
{{- end -}}
{{- end -}}

{{- define "elasticsearch.esMajorVersion" -}}
{{- if .Values.esMajorVersion -}}
{{ .Values.esMajorVersion }}
Expand Down
13 changes: 3 additions & 10 deletions elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,12 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if eq .Values.roles.master "true" }}
{{- if ge (int (include "elasticsearch.esMajorVersion" .)) 7 }}
{{- if has "master" .Values.roles }}
- name: cluster.initial_master_nodes
value: "{{ template "elasticsearch.endpoints" . }}"
{{- else }}
- name: discovery.zen.minimum_master_nodes
value: "{{ .Values.minimumMasterNodes }}"
{{- end }}
{{- end }}
- name: node.roles
value: "{{ template "elasticsearch.roles" . }}"
{{- if lt (int (include "elasticsearch.esMajorVersion" .)) 7 }}
- name: discovery.zen.ping.unicast.hosts
value: "{{ template "elasticsearch.masterService" . }}-headless"
Expand All @@ -319,10 +316,6 @@ spec:
- name: ES_JAVA_OPTS
value: "{{ .Values.esJavaOpts }}"
{{- end }}
{{- range $role, $enabled := .Values.roles }}
- name: node.{{ $role }}
value: "{{ $enabled }}"
{{- end }}
{{- if .Values.extraEnvs }}
{{ toYaml .Values.extraEnvs | indent 10 }}
{{- end }}
Expand Down
24 changes: 7 additions & 17 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def test_defaults():
{"name": "discovery.seed_hosts", "value": uname + "-headless"},
{"name": "network.host", "value": "0.0.0.0"},
{"name": "cluster.name", "value": clusterName},
{"name": "node.master", "value": "true"},
{"name": "node.data", "value": "true"},
{"name": "node.ingest", "value": "true"},
{
"name": "node.roles",
"value": "master,data,data_content,data_hot,data_warm,data_cold,ingest,ml,remote_cluster_client,transform,",
},
]

c = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]
Expand Down Expand Up @@ -174,7 +175,7 @@ def test_overriding_the_image_and_tag():
def test_set_initial_master_nodes():
config = """
roles:
master: "true"
- master
"""
r = helm_template(config)
env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"]
Expand All @@ -192,7 +193,7 @@ def test_set_initial_master_nodes():
def test_dont_set_initial_master_nodes_if_not_master():
config = """
roles:
master: "false"
- data
"""
r = helm_template(config)
env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"]
Expand All @@ -203,7 +204,7 @@ def test_dont_set_initial_master_nodes_if_not_master():
def test_set_discovery_seed_host():
config = """
roles:
master: "true"
- master
"""
r = helm_template(config)
env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"]
Expand All @@ -216,17 +217,6 @@ def test_set_discovery_seed_host():
assert e["name"] != "discovery.zen.ping.unicast.hosts"


def test_enabling_machine_learning_role():
config = """
roles:
ml: "true"
"""
r = helm_template(config)
env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"]

assert {"name": "node.ml", "value": "true"} in env


def test_adding_extra_env_vars():
config = """
extraEnvs:
Expand Down
18 changes: 12 additions & 6 deletions elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ nodeGroup: "master"
masterService: ""

# Elasticsearch roles that will be applied to this nodeGroup
# These will be set as environment variables. E.g. node.master=true
# These will be set as environment variables. E.g. node.roles=master
# https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#node-roles
roles:
master: "true"
ingest: "true"
data: "true"
remote_cluster_client: "true"
ml: "true"
- master
- data
- data_content
- data_hot
- data_warm
- data_cold
- ingest
- ml
- remote_cluster_client
- transform

replicas: 3
minimumMasterNodes: 2
Expand Down

0 comments on commit 0626843

Please sign in to comment.