securityContext

By default, Kubernetes recursively changes ownership and permissions for the contents of each volume to match the fsGroup specified in a Pod’s securityContext when that volume is mounted. For large volumes, checking and changing ownership and permissions can take a lot of time, slowing Pod startup. You can use the fsGroupChangePolicy field inside a securityContext to control the way that Kubernetes checks and manages ownership and permissions for a volume.

This does not work with hostPath-type volumes.

local volume setup on Linux calls SetVolumeOwnership(), which respects securityContext.

K3s

Rancher’s local-path-provisioner is based on hostPath by default, so it’s recommended to add annotations to the StorageClass which specify defaultVolumeType.

annotations:
  defaultVolumeType: <local or hostPath>

Alternatively, Longhorn can be installed as the CSI.

References