手动 AKS PV 失败并出现 "New-SmbGlobalMapping MountVolume.SetUp failed for volume" 错误

Manual AKS PV fails with "New-SmbGlobalMapping MountVolume.SetUp failed for volume" error

我正在尝试在 Windows AKS pod 上安装 azureFile 卷,但出现错误:

kubelet, MountVolume.SetUp failed for volume "fileshare" : New-SmbGlobalMapping failed: fork/exec C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe: The parameter is incorrect., output: ""

我的 pod.yml 看起来像:

apiVersion: v1
kind: Pod
metadata:
  name: q-pod-sample-03
  namespace: mq
spec:
  containers:
  - image: test.azurecr.io/q/p:01
    name: q-ctr-sample-03
    imagePullPolicy: "IfNotPresent"
    volumeMounts:
      - name: azfileshare
        mountPath: 'c:/app/app-data' 
  nodeSelector:
    "beta.kubernetes.io/os": windows
  volumes:
  - name: azfs
    azureFile:
      secretName: qastapv-share-01-secret
      shareName: qastapv-share-01
      readOnly: false

我的 secret.yml 看起来像:

apiVersion: v1
kind: Secret
metadata:
  name: qastapv-share-01-secret
  namespace: mq
type: Opaque
data:
  azurestorageaccountname: <Base64Str>
  azurestorageaccountkey: <Base64Str>

我的 PV 是这样的:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-azfs-q-01
  namespace: mq
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  azureFile:
    secretName: qastapv-share-01-secret
    shareName: qastapv-share-01
    readOnly: false
  mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000

我在这里缺少什么? 我正在使用 AKS 1.14。

据我所知,您的 yaml 文件有问题。首先,在您的 pod yaml 文件中:

apiVersion: v1
kind: Pod
metadata:
  name: q-pod-sample-03
  namespace: mq
spec:
  containers:
  - image: test.azurecr.io/q/p:01
    name: q-ctr-sample-03
    imagePullPolicy: "IfNotPresent"
    volumeMounts:
      - name: azfileshare
        mountPath: 'c:/app/app-data' 
  nodeSelector:
    "beta.kubernetes.io/os": windows
  volumes:
  - name: azfileshare         # this name should be the same with the name in volumeMounts
    azureFile:
      secretName: qastapv-share-01-secret
      shareName: qastapv-share-01
      readOnly: false

而且我不知道你如何将存储帐户名称和密钥转换为base64。因此,我还展示了两种在 AKS 中创建机密的方法。

一种是使用如下命令创建:

kubectl create secret generic azure-secret --from-literal=azurestorageaccountname=$AKS_PERS_STORAGE_ACCOUNT_NAME --from-literal=azurestorageaccountkey=$STORAGE_KEY

第二种是使用yaml文件,将存储账户名和密钥转换为base64,然后在yaml文件中输入如下:

echo 'storageAccountName' | base64
echo 'storageAccountKey' | base64

您显示并输入上述命令的输出的 yaml 文件。

按以上步骤即可,不需要创建PV个体

有关详细信息,请参阅 Manually create and use a volume with Azure Files share in Azure Kubernetes Service (AKS). And if you want to use the PV/PVC, take a look at Mount volumes via PV and PVC

更新:

如果使用yaml文件创建secret,还需要注意字符串转base64的操作系统。不同的操作系统可能对base64有不同的规则。对于你,你使用Windows节点,所以你需要在Windows系统上将存储帐户名称和密钥转换为base64。下面是要转换的 PowerShell 命令:

$Name= [System.Text.Encoding]::UTF8.GetBytes("storageAccountName ")
[System.Convert]::ToBase64String($Name )
$Key = [System.Text.Encoding]::UTF8.GetBytes("storageAccountKey")
[System.Convert]::ToBase64String($Key)