我重现了您所需的场景,并且能够通过静态配置将文件共享装载到 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