Cannot delete files inside K8s container within mounted Azure File Share

11/2/2020

I have a problem when deleting files inside container. Here is the command I execute via kubectl:

kubectl exec mypod-7ddbbb6c87-cwl76 -- ls -lat /usr/bin/myprogram/logs
-rwxrwxrwx 1 1000 1000   186446 Oct 22 12:59 mylogfile.log

kubectl exec mypod-7ddbbb6c87-cwl76 -- find /usr/bin/myprogram/logs -type f -mtime +14 -delete
find: cannot delete '/usr/bin/myprogram/logs/mylogfile.log': No such file or directory

I cannot understand what is the problem?

This directory /usr/bin/myprogram/logs is volume mount of Azure File Share. This AzureFileShare is used for multiple deployments\pods therefore PV is ReadWriteMany Here the part of my Yaml configuration

    kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: mypod-logs
provisioner: kubernetes.io/azure-file
reclaimPolicy: Retain
allowVolumeExpansion: true
parameters:
  skuName: Standard_LRS
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mypod-logs
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  storageClassName: mypod-logs
  azureFile:
    secretName: '#{AzureFileShareSecretName}'
    shareName: mypod-logs
    readOnly: false
  mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
  - mfsymlinks
  - nobrl
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypod-logs
spec:
  accessModes:
  - ReadWriteMany
  storageClassName: mypod-logs
  resources:
    requests:
      storage: 5Gi
---
volumeMounts:
	- readOnly: false
	  mountPath: /usr/bin/myprogram/logs
	  name: mypod-logs
volumes:
	- name: mypod-logs
	persistentVolumeClaim:
	  claimName: mypod-logs
-- user261226
azure
azure-aks
azure-blob-storage
kubernetes
linux

1 Answer

11/3/2020

All the things work fine on my side as the screenshot below shows:

enter image description here

But I met the same issue before. You can try to execute the command like this:

kubectl exec mypod-7ddbbb6c87-cwl76 -- bash -c "find /usr/bin/myprogram/logs -type f -mtime +14 -delete"
-- Charles Xu
Source: StackOverflow