CrashLoopBackOff when deploying elasticsearch using kubernetes

Posted on

When we deploy elasticsearch via kubernetes, sometimes we might get CrashLoopBackOff.

We could use kubectl logs $elasticPodName to know more details. And here are some error I found in log:

And I found a way to solve it, which is add some preporcess for init containers.

Here is the config:

  initContainers:
    - name: fix-permissions
      image: busybox
      imagePullPolicy: IfNotPresent
      command: ["sh", "-c", "mkdir -p /elasticsearch/data && chown -R 1000:1000 /elasticsearch"]
      securityContext:
        privileged: true
      volumeMounts:
        - name: news-search
          mountPath: /elasticsearch
          subPath: elasticsearch
    - name: increase-vm-max-map
      image: busybox
      imagePullPolicy: IfNotPresent
      command: ["sysctl", "-w", "vm.max_map_count=262144"]
      securityContext:
        privileged: true
    - name: increase-fd-ulimit
      image: busybox
      imagePullPolicy: IfNotPresent
      command: ["sh", "-c", "ulimit -n 65536"]
      securityContext:
        privileged: true