Azure Lei Zhang的博客

weibo: LeiZhang的微博/QQ: 185165016/QQ群:319036205/邮箱:leizhang1984@outlook.com/TeL:139-161-22926

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  489 随笔 :: 0 文章 :: 417 评论 :: 70万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

  《Windows Azure Platform 系列文章目录

  

  在Azure AKS中,可以挂载Azure File作为存储卷。

  主要分为三个步骤:

  1.创建Azure 存储账户,Azure File和AKS Secret

  2.创建PV和PVC

  3.创建pod并挂载Azure File

 

  1.首先,我们在Azure CLI运行下面的命令。

  主要作用是创建新的Azure存储账户,并在该存储账户下,创建Azure File

复制代码
az cloud set --name AzureChinaCloud
az login

# 修改下面的参数,会创建新的Azure存储账户
AKS_PERS_STORAGE_ACCOUNT_NAME=leiaks01storage
AKS_PERS_RESOURCE_GROUP=MC_aks-rg_leiaks01_chinaeast2
AKS_PERS_LOCATION=chinaeast2
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


# 创建AKS Secret
kubectl create secret generic azure-secret --from-literal=azurestorageaccountname=$AKS_PERS_STORAGE_ACCOUNT_NAME --from-literal=azurestorageaccountkey=$STORAGE_KEY

#cd /mnt/d/Work/Doc/FY21/Customer/swire/AKS/aksfile
复制代码

 

  2.使用kubectl 创建pv,如下图:

复制代码
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
复制代码

  执行完毕后,我们执行命令:

kubectl get pv

  执行结果,可以查看到pv

 

  3.使用kubectl 创建pvc,如下图:

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

  执行完毕后,我们执行命令:

kubectl get pvc

  可以查看到pvc

  

 

  4.最后,我们创建一个pod,并挂载pvc。

  注意,挂载到pod上的路径是:/mnt/azure

复制代码
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
复制代码

 

  我们执行kubectl get pod,可以查看到创建成功的pod

 

  我们可以执行命令:

kubectl exec mypod touch /mnt/azure/hello

  在Azure File里创建1个新的文件,文件名为hello。

  这个文件可以在Azure Portal里面查看到,截图略。

 

 

  或者我们可以使用下面的命令,通过交互式命令访问到pod

复制代码
#交互式命令,访问pod
kubectl exec -it mypod -- sh

#创建文件
/ # cd /mnt/azure
/mnt/azure # touch file1.txt

#查询这个文件
/mnt/azure # ls
file1.txt
复制代码

  这个文件可以在Azure Portal里面查看到,截图略。

 

posted on   Lei Zhang的博客  阅读(715)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示