<p>I'm trying to deployment ES to kubernetes, I did these steps before apply to kube</p>
<ol>
<li>Dockerization on my local machine</li>
</ol>
<pre><code>docker run -d --net devnet \
--name my-elastic \
--env ES_JAVA_OPTS=&quot;-Xms512m -Xmx512m&quot; \
--env ES_PROTOCOL=&quot;http&quot; \
--env discovery.type=single-node \
--env xpack.security.enabled=false \
--env ELASTIC_APM_VERIFY_SERVER_CERT=false \
--env XPACK_LICENSE_SELF_GENERATED_TYPE=&quot;basic&quot; \
-p 9200:9200 -p 9300:9300 -it asia.gcr.io/my-project/elasticsearch:latest
</code></pre>
<ul>
<li>I use JVM heap size 512m, because it's not for production</li>
<li>I disable verify cert &amp; xpack security and use <code>http</code> protocol because still try non zero trust in my cluster</li>
<li>In my local that's running well</li>
</ul>
<ol start="2">
<li>I have created GCE persistent disk for data</li>
<li>I have created volume and claimed the persistent disk volume</li>
</ol>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-elasticsearch-pv
spec:
  storageClassName: &quot;&quot;
  capacity:
    storage: 10G
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  claimRef:
    namespace: default
    name: my-elasticsearch-pvc
  gcePersistentDisk:
    pdName: es-disk
    fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-elasticsearch-pvc
spec:
  storageClassName: &quot;&quot;
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10G
</code></pre>
<ol start="4">
<li>I have created &amp; applied the service</li>
</ol>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-elastic
spec:
  ports:
  - name: http-port
    port: 9200
    targetPort: es-port
  selector:
    app: my-elastic
  type: ClusterIP
</code></pre>
<ol start="5">
<li>Create deployment file and apply this setup</li>
</ol>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-elastic
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-elastic
  template:
    metadata:
      labels:
        app: my-elastic
    spec:
      containers:
      - name: my-elastic
        resources:
            requests:
                memory: 1Gi
        image: asia.gcr.io/my-project/elasticsearch:latest
        env:
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        - name: ES_PROTOCOL
          value: http
        - name: discovery.type
          value: single-node
        - name: XPACK_LICENSE_SELF_GENERATED_TYPE
          value: basic
        - name: xpack.security.enabled
          value: 'false'
        - name: xpack.monitoring.enabled
          value: 'false'
        ports:
        - name: es-port
          containerPort: 9200
        volumeMounts:
        - name: my-elasticsearch-data
          mountPath: /usr/share/elasticsearch/data
      volumes:
      - name: my-elasticsearch-data
        persistentVolumeClaim:
          claimName: my-elasticsearch-pvc
</code></pre>
<p>I got <code>CrashLoopBackOff</code> after applied the deployment, this is the condition of my cluster. Did I missing something on the config?</p>
<p><a href="https://i.stack.imgur.com/y8wuV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y8wuV.png" alt="enter image description here" /></a></p>
<p>Here is the logs</p>
<pre><code>&quot;log.level&quot;:&quot;ERROR&quot;, &quot;message&quot;:&quot;uncaught exception in thread [main]&quot;, &quot;ecs.version&quot;: &quot;1.2.0&quot;,&quot;service.name&quot;:&quot;ES_ECS&quot;,&quot;event.dataset&quot;:&quot;elasticsearch.server&quot;,&quot;process.thread.name&quot;:&quot;main&quot;,&quot;log.logger&quot;:&quot;org.elasticsearch.bootstrap.ElasticsearchUncaughtExceptionHandler&quot;,&quot;elasticsearch.node.name&quot;:&quot;alodokter-emr-es-5cbd4cd95-bfvld&quot;,&quot;elasticsearch.cluster.name&quot;:&quot;docker-cluster&quot;,&quot;error.type&quot;:&quot;org.elasticsearch.bootstrap.StartupException&quot;,&quot;error.message&quot;:&quot;java.lang.IllegalStateException: failed to obtain node locks, tried [/usr/share/elasticsearch/data]; maybe these locations are not writable or multiple nodes were started on the same data path?&quot;
</code></pre>

itx
<p>Make Elasticsearch (UID: <code>1000</code>) owner of the data directory <code>/usr/share/elasticsearch/data</code> from an initContainer.</p>
<pre class="lang-bash prettyprint-override"><code>$ chown -R 1000:1000 /usr/share/elasticsearch/data
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-elastic
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-elastic
  template:
    metadata:
      labels:
        app: my-elastic
    spec:
      initContainers:
      - name: busybox
        image: busybox:1.28
        command: ['sh', '-c', &quot;chown -R 1000:1000 /usr/share/elasticsearch/data&quot;]
        volumeMounts:
        - name: my-elasticsearch-data
          mountPath: /usr/share/elasticsearch/data
      containers:
      - name: my-elastic
        resources:
            requests:
                memory: 1Gi
        image: asia.gcr.io/my-project/elasticsearch:latest
        env:
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        - name: ES_PROTOCOL
          value: http
        - name: discovery.type
          value: single-node
        - name: XPACK_LICENSE_SELF_GENERATED_TYPE
          value: basic
        - name: xpack.security.enabled
          value: 'false'
        - name: xpack.monitoring.enabled
          value: 'false'
        ports:
        - name: es-port
          containerPort: 9200
        volumeMounts:
        - name: my-elasticsearch-data
          mountPath: /usr/share/elasticsearch/data
      volumes:
      - name: my-elasticsearch-data
        persistentVolumeClaim:
          claimName: my-elasticsearch-pvc
</code></pre>
