Kubernetes: Mounting SMB Shares in Windows Containers

If you need to mount an SMB share inside a Windows container, you can use this thing.

In short, you first need to set up the Windows nodes of the cluster themselves. This is done by copying the folder here: C:\usr\libexec\kubernetes\kubelet-plugins\volume\exec\

Then create a secret with the username and password (base64-encoded):

apiVersion: v1
kind: Secret
metadata:
  name: smb-secret
data:
  password: cGFzc3dvcmQ=
  username: dXNlcm5hbWU=
type: microsoft.com/smb.cmd

And now you can mount a volume like this:

apiVersion: v1
kind: Pod
metadata:
  name: smb
  namespace: default
spec:
  restartPolicy: Never
  containers:
  - name: smb
    image: microsoft/nanoserver
    command: ["C:\\Windows\\System32\\cmd.exe"]
    args: ["/C", "echo", "0", ">", "c:\\d\\smb_test.txt"]
    volumeMounts:
    - name: smb-volume
      mountPath: /d
  volumes:
  - name: smb-volume
    flexVolume:
      driver: "microsoft.com/smb.cmd"
      secretRef:
        name: "smb-secret"
      options:
        # source can be in any of the following formats
        # \\servername\share\path  (\'s will need to be escaped)
        # smb://servername/share/path
        # //servername/share/path
        source: "\\\\Server\\Share\\optional\\sub\\path"

PS: For Linux pods, a similar solution will do: https://github.com/fstab/cifs

Only registered users can leave a comment.

Sign in or register to leave a comment.