Loading

Custom configuration files and plugins

This page covers two of the approaches described in Add plugins and configuration files in Elastic Cloud on Kubernetes: including Elasticsearch plugins in a custom container image, and injecting configuration files with ConfigMaps or Secrets.

Refer to Creating custom images for instructions on how to build custom Docker images based on the official Elastic images. Install the plugins you need in the image so they are available when the Elasticsearch container starts.

To install custom configuration files you can:

  1. Add the configuration data into a ConfigMap or Secret.
  2. Use volumes and volume mounts in your manifest to mount the contents of the ConfigMap or Secret as files in your Elasticsearch nodes.

The next example shows how to add a synonyms file for the synonym token filter in Elasticsearch. But you can use the same approach for any kind of file you want to mount into the configuration directory of Elasticsearch, like adding CA certificates of external systems.

  1. Create the ConfigMap or Secret with the data:

There are multiple ways to create and mount ConfigMaps and Secrets on Kubernetes. Refer to the official documentation for more details.

This example shows how to create a ConfigMap named synonyms with the content of a local file named my-synonyms.txt added into the synonyms-elasticsearch.txt key of the ConfigMap.

kubectl create configmap synonyms -n <namespace> --from-file=my-synonyms.txt=synonyms-elasticsearch.txt
		
Tip

Create the ConfigMap or Secret in the same namespace where your Elasticsearch cluster runs.

  1. Declare the ConfigMap as a volume and mount it in the Elasticsearch containers.

In this example, modify your Elasticsearch manifest to mount the contents of the synonyms ConfigMap into /usr/share/elasticsearch/config/dictionaries on the Elasticsearch nodes.

spec:
  nodeSets:
  - name: default
    count: 3
    podTemplate:
      spec:
        containers:
        - name: elasticsearch
          volumeMounts:
          - name: synonyms
            mountPath: /usr/share/elasticsearch/config/dictionaries
        volumes:
        - name: synonyms
          configMap:
            name: synonyms
		
  1. Elasticsearch runs by convention in a container called elasticsearch. Do not change that value.
  2. Use always a path under /usr/share/elasticsearch/config.
  3. Use secret instead of configMap if you used a secret to store the data.
  4. The ConfigMap name must be the same as the ConfigMap created in the previous step.

After the changes are applied, Elasticsearch nodes should be able to access dictionaries/synonyms-elasticsearch.txt and use it in any configuration setting.

Note

ConfigMaps and Secrets are for configuration files only. Mounting plugin files does not install them. To install plugins, use a custom image or init containers.