【问题标题】:Manual AKS PV fails with "New-SmbGlobalMapping MountVolume.SetUp failed for volume" error手动 AKS PV 失败并出现“New-SmbGlobalMapping MountVolume.SetUp failed for volume”错误
【发布时间】:2019-07-19 14:02:14
【问题描述】:

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

kubelet,MountVolume.SetUp 对卷“fileshare”失败: New-SmbGlobalMapping 失败:fork/exec C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe: 参数不正确,输出:""

我的 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。

【问题讨论】:

    标签: kubernetes azure-aks


    【解决方案1】:

    如我所见,您的 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文件,将存储账户名和key转换成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)。如果您想使用 PV/PVC,请查看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)
    

    【讨论】:

    • Pod 创建再次失败:**MountVolume.SetUp 卷“azfileshare”失败:New-SmbGlobalMapping 失败:退出状态 1,输出:“New-SmbGlobalMapping:参数不正确。\r\nAt line:1 char:190\r\n+ ... ser, $PWord;New-SmbGlobalMapping -RemotePath $Env:smbremotepath -Cred ...\r\n+~~~~~~~~~~\r\n + CategoryInfo : InvalidArgument: (MSFT_SmbGlobalMapping:ROOT/Microsoft/...mbGlobalMapping) [New-SmbGloba \r\n lMapping], CimException\r\n + FullyQualifiedErrorId : Windows 系统错误 87,New-SmbGlobalMapping\r\n \r \n" **
    • 如果我从 cmdline 创建秘密,那么它可以工作。但现在不同的错误:** 无法提取图像“test.azurecr.io/q/p:01”:rpc 错误:代码 = 未知 desc = 来自守护进程的错误响应:获取 test.azurecr.io/v2/q/p/manifests/01:未授权:需要身份验证 ** I按照here 所述的步骤进行操作
    • @Sam 这是一个正常的错误。您可以检查是否使用了错误的图像。如果 AKS 在其访问控制中被允许,您还需要检查 ACR。
    • @Sam 我更新了使用 yaml 文件创建机密的答案。您因操作系统而收到的错误。
    • 我没有意识到我需要同时转换密钥和名称。但现在它就像一个魅力。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    相关资源
    最近更新 更多