Kubernetes access Network Fileshare

10/9/2018

Recently we have started using Kubernetes as a path for moving forward with new projects. We started implementing some of them and we are now struggling with one issue. How to access network file share ?

Our Kubernetes cluster is linux based cluster installed on Windows machine. Services hosted in that cluster need to be able to access file share which is accessible on that machine (i.e. \\myFileShare\myfolder ).

We can't find a solution to this one. We have tried using "https://www.nuget.org/packages/SharpCifs.Std/" library to acccess the files over SMB but it turned out it, the library won't support SMB 2.0.

We were also thinking about mounting this drive as Persistent Volume but if i understand correctly persistent volume is supposed to have its lifecycle managed by Kubernetes so i don't think it's designed for this kind of stuff.

We have tried to find solution in the internet but we didn't find anything, but i'm pretty sure we are not the first people who need to access Network fileshare from Kuberenetes cluster. Did anyone struggle with this problem before and could provide us some solution to that one ?

-- MajkeloDev
.net-core
kubernetes

1 Answer

10/10/2018

Have a look at cifs-volumedriver or this Kubernetes CIFS Volume Driver. It should apply to your case, and it works with SMB2.1 The following is an example of PersistentVolume that uses the volume driver.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mycifspv
spec:
  capacity:
    storage: 1Gi
  flexVolume:
    driver: juliohm/cifs
    options:
      opts: sec=ntlm,uid=1000
      server: my-cifs-host
      share: /MySharedDirectory
    secretRef:
      name: my-secret
  accessModes:
    - ReadWriteMany

Credentials are passed using a Secret, which can be declared as follows:

apiVersion: v1
data:
  password: ###
  username: ###
kind: Secret
metadata:
  name: my-secret
type: juliohm/cifs

NOTE: Pay attention to the secret's type field, which MUST match the volume driver name. Otherwise the secret values will not be passed to the mount script.

Also, please take a look at this question on Stack. Its author has the same problem and shows how to solve it.

-- Nick Rak
Source: StackOverflow