Kubernetes ConfigMap directory permissions

12/19/2017

I want to configure elasticsearch with the elasticsearch.yml, located in /usr/share/elasticsearch/config. I am doing this via a ConfigMap which I mount into the container.

That does not work due to k8s takes over the control of this directory and the other files of that directory does not exist anymore (eg jvm.options).

I think that is a common issue - is there a best practice to fix this? The first idea which came to my mind was symlinking to /some/other/directory/elasticsearch.yml with an initcontainer. Is that wise to do so?

-- Hubert Ströbitzer
elasticsearch
kubernetes

1 Answer

12/19/2017

So found a proper solution I want to share with you. The magic happens with the subPath in the volumeMount

apiVersion: v1
kind: ConfigMap
...
data:
  elasticsearch.yml: |
    xpack.license.self_generated.type: basic
---
apiVersion: extensions/v1beta1
kind: Deployment
...
spec:
  ...
  template:
    containers:
      ...
    volumeMounts:
      - name: config
        mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
        subPath: elasticsearch.yml
  volumes:
    - name: config
      configMap:
        name: elasticsearch-logging
-- Hubert Ströbitzer
Source: StackOverflow