【问题标题】:Azure blob container mounting to AKS deployment errorAzure blob 容器安装到 AKS 部署错误
【发布时间】:2021-12-04 18:03:49
【问题描述】:

活动: 类型原因年龄来自消息


Normal Scheduled 44s default-scheduler 成功将 fcc-p​​oc/fccapp-5cd844c68d-55gpc 分配给 aks-l21d11107014-59385960-vmss00007d 警告 FailedAttachVolume 10s (x7 over 44s) attachdetach-controller AttachVolume.Attach 卷“afs-fcc-appdata”失败:Retriable:false,RetryAfter:0s,HTTPStatusCode:400,RawError:Retriable:false,RetryAfter:0s,HTTPStatusCode:400 ,原始错误:{ “错误”: { "code": "无效参数", "message": "缺少必需的参数 'dataDisk.managedDisk' (null)。", “目标”:“dataDisk.managedDisk” } }

【问题讨论】:

  • 你能告诉我你关注的是哪个文件吗?
  • 我指的是多个文档,尤其是 MS 文档。 docs.microsoft.com/en-us/azure/aks/concepts-storage 除了这个文档,我还创建了 PV,因为我不需要动态配置。
  • 你好 Arun,如果我的回答对你有帮助,你可以接受它作为答案(点击答案旁边的复选标记,将它从灰色切换为填充。)。这对其他社区成员可能是有益的。谢谢

标签: azure-blob-storage azure-aks


【解决方案1】:

我重现了您所需的场景,并且能够通过静态配置将文件共享装载到 AKS Pod。

只有在 azure 中,我们才能在 PV 的帮助下将文件共享或 Azure 托管磁盘挂载到 AKS pod,并且您所引用的文档是用于相同用途的。

请按照以下步骤申请。

第 1 步:创建 Azure 文件共享 Azure 文件共享

 # Change these four parameters as needed for your own environment
AKS_PERS_STORAGE_ACCOUNT_NAME=rahulstorageaccount7735
AKS_PERS_RESOURCE_GROUP=v-ra&&1*-Mi*****
AKS_PERS_LOCATION=eastus
AKS_PERS_SHARE_NAME=aksshare

# Create a resource group
#az group create --name $AKS_PERS_RESOURCE_GROUP --location $AKS_PERS_LOCATION

# Create a storage account
az storage account create -n $AKS_PERS_STORAGE_ACCOUNT_NAME -g $AKS_PERS_RESOURCE_GROUP -l $AKS_PERS_LOCATION --sku Standard_LRS

# Export the connection string as an environment variable, this is used when creating the Azure file share
export AZURE_STORAGE_CONNECTION_STRING=$(az storage account show-connection-string -n $AKS_PERS_STORAGE_ACCOUNT_NAME -g $AKS_PERS_RESOURCE_GROUP -o tsv)

# Create the file share
az storage share create -n $AKS_PERS_SHARE_NAME --connection-string $AZURE_STORAGE_CONNECTION_STRING

# Get storage account key
STORAGE_KEY=$(az storage account keys list --resource-group $AKS_PERS_RESOURCE_GROUP --account-name $AKS_PERS_STORAGE_ACCOUNT_NAME --query "[0].value" -o tsv)

# Echo storage account name and key
echo Storage account name: $AKS_PERS_STORAGE_ACCOUNT_NAME
echo Storage account key: $STORAGE_KEY

第 2 步:创建 Kubernetes 密钥

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

还会创建一个包含存储帐户密钥的 Kubernetes 机密。使用以下命令获取机密。

kubectl get secrets

第 3 步:将文件共享挂载为永久卷

要将 Azure 文件共享装载到您的 pod,请在容器规范中配置卷。 要更新挂载选项,请使用 PersistentVolume 创建一个 azurefile-mount-options-pv.yaml 文件。例如:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: azurefile
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  azureFile:
    secretName: azure-secret
    shareName: aksshare
    readOnly: false
  mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
  - mfsymlinks
  - nobrl

使用 PersistentVolumeClaim 创建一个 azurefile-mount-options-pvc.yaml 文件,该文件使用 PersistentVolume。例如:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azurefile
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi

使用 kubectl 命令创建 PersistentVolume 和 PersistentVolumeClaim。

kubectl apply -f azurefile-mount-options-pv.yaml
kubectl apply -f azurefile-mount-options-pvc.yaml

使用 mypod 创建一个 app-pod.yaml 文件,例如:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    name: mypod
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 256Mi
    volumeMounts:
      - name: azure
        mountPath: /mnt/azure
  volumes:
  - name: azure
    persistentVolumeClaim:
      claimName: azurefile
    # azureFile:
      # secretName: azure-secret
      # shareName: aksshare
      # readOnly: false

部署示例 Nginx Pod 并将其附加到文件共享

kubectl apply -f app-pod.yaml


# Test access to File Share from the Pod: 
   kubectl exec pod/nginx -it -- /bin/sh
# From inside the Pod shell:
# ls /mnt/azure
# echo "Hello from Azure File Share" > /mnt/azure/myfile.txt
# ls /mnt/azure
# cat /mnt/azure/myfile.txt

OutPut : 从 Azure 门户上传了一个文件,并且可以通过 pod 看到该文件。因此它已成功挂载

参考:https://docs.microsoft.com/en-us/azure/aks/azure-files-volume https://github.com/HoussemDellai/aks-file-share

【讨论】:

    猜你喜欢
    • 2019-11-05
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    相关资源
    最近更新 更多