<p>Azure Kubernetes service is giving recommendation- mutable (read-only) root filesystem should be enforced for containers</p>
<p>My deployment is working as expected without it but after adding   <code>readOnlyRootFilesystem: true</code> It's not working because the container can not write.</p>
<p>I am also using PVC with azure storage files and It shows successful binding but It always shows empty.</p>
<p>Here is my deployment.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-healthy-deployment
  labels:
    app: redis
spec:
  replicas: 3
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
      annotations:
        container.apparmor.security.beta.kubernetes.io/redis: runtime/default
    spec:
      containers:
      - name: redis
        image: &lt;customer-registry&gt;.azurecr.io/redis:latest
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: 100m
            memory: 250Mi
        securityContext:
          privileged: false
          readOnlyRootFilesystem: true
          allowPrivilegeEscalation: false
          runAsNonRoot: true
          runAsUser: 1000
       volumeMounts:
       - mountPath: &quot;/mnt/azure&quot;
         name: volume
       - mountPath: &quot;mnt/secrets-store&quot;
         name: secrets-mount
         readOnly: true
   volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: helloworld-pvc 
    - name: secrets-mount
      csi:
        driver: secrets-store.csi.k8s.io
        readOnly: true
        volumeAttributes:
          secretProviderClass: &quot;azure-keyvault&quot;
</code></pre>
<p>and here are the errors from pod :</p>
<pre><code>rm: can't remove '/home/test/mi-4.0.0/tmp/README': Read-only file system
rm: can't remove '/home/test/mi-4.0.0/tmp/work': Read-only file system
</code></pre>
<p>If I am using PVC then doesn't pod/container should write to PVC ??</p>
<p>I will really appreciate it if someone can help fix this.
I am happy to provide more details</p>

megha
<p>It's true that read-only file system is preferable, if possible. However, some application need to write to data to disk, for one or another reason.</p>
<p>Your error is not regarding the mounted volume, but regarding the <code>/tmp</code> directory.</p>
<p>You can keep your read only file system am make only that part writable by mounting an <a href="https://kubernetes.io/docs/concepts/storage/volumes/#emptydir" rel="nofollow noreferrer">empty dir</a> volume to this path.</p>
<pre><code>volumes:
  - name: tmp
    emptyDir: {}
</code></pre>
<pre><code>volumeMounts:
  - name: tmp
    mountPath: /home/test/mi-4.0.0/tmp
</code></pre>
<p>Note that the volume will overwrite the location where is being mounted to. If you need data in this directory when the container starts, you could opt for an initContainer that mounts the same volume and adds the required files to it.</p>
