简体   繁体   中英

Kubernetes - cannot have Windows path mounted on Azure File Share (Linux mounting works properly )

Firstly I succesfully mounted, my Linux path on Pod. I used azure file share and mounted folders appear on File Share.

    volumeMounts:
      - name: ads-filesharevolume
        mountPath: /opt/front/arena/host
  volumes:
  - name: ads-filesharevolume
    azureFile:
      secretName: fa-fileshare-secret
      shareName: faselectaksshare
      readOnly: false

Now on File Share I added one subfolder "windows" for mounting, in logs it mentions it is being mounted properly but I do not have anything mounted (folders and files do not appear on mounted share like it is the case for Linux)

   args: [ "-license_file", "C:/Host/dat/license.dat",
           "-key_file", "C:/Host/dat/license.key"]
    volumeMounts:
      - name: ads-win-filesharevolume
        mountPath: "C:\\host"
  volumes:
  - name: ads-win-filesharevolume
    azureFile:
      secretName: fa-fileshare-secret
      shareName: faselectaksshare\windows
      readOnly: false

For mountPath I tried with: C:\\host and C:/host and /c/host Also for shareName I initially tried with faselectaksshare/windows but it threw an exception.

In Pod describe I can see that everything seems OK, but my expected folders from C:/host do not appear in my Azure File Share path in windows subfolder. I receive similar output for all other cases as well.

 Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-nx49r (ro)
      C:/host from ads-win-filesharevolume (rw)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  ads-win-filesharevolume:
    Type:        AzureFile (an Azure File Service mount on the host and bind mount to the pod)
    SecretName:  fa-fileshare-secret
    ShareName:   faselectaksshare\windows
    ReadOnly:    false

Please help! Thanks

UPDATE: I also tried this approach with subPath and again I do not get any folders mounted. Also I do not get any error in log or in describe pod command

volumeMounts:
  - name: ads-filesharevolume
    mountPath: /host
    subPath: windows
  volumes:
  - name: ads-filesharevolume
    azureFile:
      secretName: fa-fileshare-secret
      shareName: faselectaksshare
      readOnly: false

Both Windows and Linux containers run at the same time:

在此处输入图像描述

Mount for Linux:

    volumeMounts:
    - name: azure
      mountPath: /mnt/azure
volumes:
  - name: azure
    azureFile:
        shareName: aksshare/linux
        secretName: azure-secret

在此处输入图像描述

Mount for Windows:

    volumeMounts:
    - name: azure
        mountPath: "C:\\fileshare"
volumes:
- name: azure
  azureFile:
  shareName: aksshare\windows
  secretName: azure-secret

在此处输入图像描述

And the files that exist in each subfolder of the file share do not affect other ones.

kubelet is supposed to mount the Azure File Share into the Container

It uses https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/mount-utils/mount_windows.go and https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/azure_file/azure_file.go

It uses SMB Mapping and then mklink to mount Azure File Share into the Container

Please start kubelet in Windows Node where the Pod is running and the Azure File Share is supposed to be mounted with --v 4 Flag so we get to see debug messages in kubelet log when it tries to mount Azure File Share into the Container. Then please provide the messages in kubelet log. You should see below messages from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/mount-utils/mount_windows.go

klog.V(3).Infof("mounting source (%q), target (%q), with options (%q)", source, target, sanitizedOptionsForLogging)

klog.V(4).Infof("mount options(%q) source:%q, target:%q, fstype:%q, begin to mount",
        sanitizedOptionsForLogging, source, target, fstype)

            klog.Warningf("SMB Mapping(%s) returned with error(%v), output(%s)", source, err, string(output))

klog.V(2).Infof("SMB Mapping(%s) already exists while it's not valid, return error: %v, now begin to remove and remount", source, err)

klog.V(2).Infof("SMB Mapping(%s) already exists and is still valid, skip error(%v)", source, err)

klog.Errorf("mklink failed: %v, source(%q) target(%q) output: %q", err, mklinkSource, target, string(output))

klog.V(2).Infof("mklink source(%q) on target(%q) successfully, output: %q", mklinkSource, target, string(output))

According to the following thread, wsl2 doesn't yet support hostPath volumes.

Thread Source: https://github.com/docker/for-win/issues/5325 Look at this comment: https://github.com/docker/for-win/issues/5325#issuecomment-570683131

Try changing this line

 # For "C://host"
 mountPath: /run/desktop/mnt/host/c/host

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM