<p>I have created the following persistent volume in GoogleCloud by deploying the following yml file:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: staging-filestore
  labels:
    filestore: standard
spec:
  capacity:
    storage: 1T
  accessModes:
  - ReadWriteMany
  mountOptions:
  - lookupcache=positive #Disables caching to make all writes be sync to the server
  nfs:
    path: /staging
    server: 10.64.16.130
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: staging-filestore-pvc
spec:
  selector:
    matchLabels:
      filestore: standard
  accessModes:
  - ReadWriteMany
  storageClassName: &quot;&quot;
  resources:
    requests:
      storage: 1T

</code></pre>
<p>The volume is created successfully and mounted in thein the service below:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: demo
  labels:
    app: demo
    vendor: rs
spec:
  selector:
    app: demo
    vendor: rs
  ports:
  - port: 4010
    name: internal
    targetPort: 4010
  - port: 80
    name: external
    targetPort: 4010
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
  labels:
    app: demo
    vendor: rs
spec:
  selector:
    matchLabels:
      app: demo
  replicas: 1
  revisionHistoryLimit: 2
  template:
    metadata:
      labels:
        app: demo
        vendor: rs
    spec:
      imagePullSecrets:
      - name: dockerhub-secret

      containers:

      - name: demo
        image: rs/demo:latest
        imagePullPolicy: Always
        resources:
          requests:
            memory: &quot;1Gi&quot;
          limits:
            memory: &quot;2Gi&quot;
        volumeMounts:
          - mountPath: /dumps/heap-dump
            name: dumpstorage
        readinessProbe:
          httpGet:
            path: /_health
            port: http
          initialDelaySeconds: 5
          periodSeconds: 5
          failureThreshold: 5
        livenessProbe:
          httpGet:
            path: /_health
            port: http
          initialDelaySeconds: 25
          periodSeconds: 5
          failureThreshold: 10
        envFrom:
        - configMapRef:
            name: rs-config
        env:
        - name: JAVA_TOOL_OPTIONS
          value: &quot; -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\&quot;/dumps/demo-heap-dump\&quot;&quot;
        ports:
        - containerPort: 4010
          name: http
      volumes:
        - name: dumpstorage
          persistentVolumeClaim:
            claimName: staging-filestore-PVC
            readOnly: false
</code></pre>
<p>I want that the heap dump generated when the application has a memory overflow error to be stored and the staging-filestore-PVC volume. To test this, I set the heap size to 1MB with the option <code>-Xmx16m</code>. The application crashes causing also the pod to crash. I can see in the logs that say the heap dump is created:</p>
<pre><code>2022-08-08 15:34:55.767 CESTDumping heap to /dumps/demo-heap-dump ...
2022-08-08 15:34:55.990 CESTHeap dump file created [26757864 bytes in 0.223 secs]
</code></pre>
<p>I deploy the service yml file again with the <code>-Xmx1G</code> option. And enter inside the pod terminal with the command <code>kubectl exec -it demo-77f84d9957-vxrsz -- sh</code>, go to the /dumps directory there is no demo-heap-dump file.
<a href="https://i.stack.imgur.com/0X3U1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0X3U1.png" alt="enter image description here" /></a></p>
<p>I am struggling to understand why the file is not present although no error is thrown and the logs say that the file is created. Thank you for the help.</p>
<p>Regards,
Rando.</p>

Rando Shtishi
<p>Try:</p>
<pre><code>...
env:
- name: JAVA_TOOL_OPTIONS
  value: &quot; -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\&quot;/dumps/heap-dump\&quot;&quot;  # &lt;-- update the path
...
</code></pre>
