zoukankan      html  css  js  c++  java
  • AKS (3) 在AKS中使用Azure File

      《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里面查看到,截图略。

  • 相关阅读:
    hdu3486 Interviewe (二分+线段树求区间最值)
    hdu2473 JunkMail Filter(并查集)
    hdu3290 The magic apple tree (dfs)
    hdu2610 Sequence one (dfs) &&hdu2611 Sequence two
    hdu1598 find the most comfortable road (枚举+并查集)
    hdu3635 Dragon Balls
    hdu2821 Pusher
    hdu1558 Segment set
    hdu 2514 Another Eight Puzzle
    url传递中文的解决方案
  • 原文地址:https://www.cnblogs.com/threestone/p/14945887.html
Copyright © 2011-2022 走看看