Modify elastic.yml file in kubernetes pod

Hello! I have an elasticsearch cluster running on minikube. When I ssh into one of the elasticsearch pods, I can see that the elasticsearch.yml file is very empty/has almost no configs set.

[elasticsearch@es-0 config]$ cat elasticsearch.yml 
cluster.name: "docker-cluster"
network.host: 0.0.0.0

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1 

I would like to add some modifications to this file. I know that I am supposed to use a ConfigMap to update this but I am confused as to how I can use the ConfigMap values to update the elasticsearch.yml config.

Currently this is my ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: elasticsearch-config
data:
  elasticsearch.yml: |
    cluster.name: elasticsearch-pod
    node.name: ${HOSTNAME}
    network.host: 0.0.0.0
    
    bootstrap.memory_lock: false
    
    discovery.zen.minimum_master_nodes: 2
    discovery.zen.ping.unicast.hosts: ["es-0", "es-1", "es-2"]

Now I would like to make sure that when my StatefulSet is created the pods use this elasticsearch.yml. I know for Pods/StatefulSets you can set the env vars by referencing keys in your ConfigMap but I don't know what env vars are used by elasticsearch.

env:
- name: ENV_VAR
          valueFrom:
            configMapKeyRef:
              name: elasticsearch-config
              key: KEY_HERE

I can't seem to find a reference doc on the elasticsearch site, do I just use the same name (Ex. env var cluster.name has key cluster.name)? Thanks!

UPDATE:

I found out that I can simply mount the MapConfig as a volume to the pods I want.

volumeMounts:
        - name: storage
          mountPath: /data
        - name: config-volume
          mountPath: /usr/share/elasticsearch/config
      volumes:
       - name: config-volume
         configMap:
          name: elasticsearch-config

But this results in errors when creating the pods:

2017-10-11 20:57:59,841 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:322)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
	at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
	at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
	at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:556)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)
	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:220)
	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)
	at org.elasticsearch.common.logging.LogConfigurator.configureStatusLogger(LogConfigurator.java:175)
	at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:143)
	at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:122)
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:307)
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132)
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134)
	at org.elasticsearch.cli.Command.main(Command.java:90)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)

ERROR: no log4j2.properties found; tried [/usr/share/elasticsearch/config] and its subdirectories

Am I mounting in the wrong spot or am I supposed to have all the required files inside my configMap? What potential issues should I look into here? Thanks!

1 Like

Fixed my issue, had the same solution as the one seen here

Basically my mount was overwriting everything else in the path so I only had my elasticsearch.yml file and all the other config files were missing. Using the subPath field fixed my issue of overwriting

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.