Deploying ElasticSearch 7 in Kubernetes or Docker
Deploying an ElasticSearch container on Kubernetes or Docker is not as easy as it was on previous version, there are some changes there and if you just deploy it on a development or staging it will fail with below error message:
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /usr/share/elasticsearch/logs/docker-cluster.log
And there is no /usr/share/elasticsearch/logs/docker-cluster.log
to check for logs, at least I could not find it.
What you need to do is to configure it to run in single-node
mode, initially I tried to do that by adding it to the ES_JAVA_OPTS
environment variable, but for some reason ElasticSearch is not honoring it.
So the solution is to mount a configuration file with the configurations you want, and that is how you can do that on Kubernetes.
Running Elasticsearch in Kubernetes
Step 1: Create a ConfigMap
Create a ConfigMap named elasticsearch-config
with your desired configuration settings. Save the following YAML to a file named elasticsearch_config.yaml
:
apiVersion: v1
kind: ConfigMap
metadata:
name: elasticsearch-config
data:
elasticsearch.yml: |
cluster.name: "my-cluster"
network.host: 0.0.0.0
discovery.type: single-node
Step 2: Create a Deployment
Next, create a Deployment YAML file named elasticsearch.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: elasticsearch:7.10.1
volumeMounts:
- name: elasticsearch-config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
subPath: elasticsearch.yml
ports:
- containerPort: 9200
volumes:
- name: elasticsearch-config
configMap:
name: elasticsearch-config
With the above you are ready to run an ElasticSearch 7 on Kubernetes, the same solution applies to docker, you will need to mount the configuration file elasticsearch.yaml
overwriting it with the settings you want, as the variable ES_JAVA_OPTS
is also not honored.
Running Elasticsearch in Docker
Create the elasticsearch.yml
file with the following content
cluster.name: "my-cluster"
network.host: 0.0.0.0
discovery.type: single-node
Run Docker with the following command:
docker run -ti \
-v $(pwd)/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
elasticsearch:7.10.1
Be happy, By Safe!