AKS (7) Azure AKS訪問Azure File NFS Windows Azure Platform 系列文章目錄

  《Windows Azure Platform 系列文章目錄

 

  今天遇到了這個需求,在這裏記錄一下。

 

  Azure Blob Storage 可以通過NFS協議,提供給Azure AKS使用。筆者在這裏使用的Azure File NFS 4協議。

  整體部署的場景如下:

  1.創建VNet環境,包含3個subnet

  (1)子網aks-subnet,用來創建AKS集羣

  (2)子網vm-subnet,用來創建Linux VM

  (3)子網nfs-subnet,用來創建nfs內網IP地址

  2.創建Azure Blob Storage和Azure File Sharing

  3.創建Private DNS Zone,對azure File增加內網DNS記錄

  

  1.Azure CLI創建Azure資源的腳本如下:

  https://github.com/leizhang1984/K8S/blob/main/1.19/16.AzureNFS/azurenfs.txt

az cloud set -n AzureChinaCloud
az login

rgname=leiaks-rg2
vnetname=aks_vnet
location=chinaeast2

#create resource group
az group create -n $rgname -l $location

#create azure vnet,including 3 subnets
az network vnet create -g $rgname -n $vnetname \
  --address-prefixes 10.0.0.0/8 --subnet-name aks-subnet \
  --subnet-prefixes 10.240.0.0/16

#subnet for VM
az network vnet subnet create -g $rgname --vnet-name $vnetname \
  -n vm-subnet --address-prefixes 10.241.0.0/24 

#subnet for nfs
az network vnet subnet create -g $rgname --vnet-name $vnetname \
  -n nfs-subnet --address-prefixes 10.241.1.0/24 

#create storage account
storageaccountname=leiaksnfsstorage02
az storage account create \
  --name $storageaccountname \
  --resource-group $rgname \
  --location $location \
  --sku Premium_LRS \
  --kind FileStorage

#deny https only
az storage account update --https-only false \
  --name $storageaccountname --resource-group $rgname

#create azure file storage with 100GB quota
az storage share-rm create \
  --storage-account $storageaccountname \
  --enabled-protocol NFS \
  --root-squash RootSquash \
  --name "aksnfsshare" \
  --quota 100

#create private endpoint
subnetid=`az network vnet subnet show \
  --resource-group $rgname \
  --vnet-name $vnetname \
  --name nfs-subnet \
  --query "id" -o tsv `

storageaccountid=`az storage account show \
  --resource-group $rgname \
  --name $storageaccountname \
  --query "id" -o tsv `

az network vnet subnet update \
  --ids $subnetid \
  --disable-private-endpoint-network-policies 

endpoint=`az network private-endpoint create \
  --resource-group $rgname \
  --name "$storageaccountname-privateendpoint" \
  --location $location \
  --subnet $subnetid \
  --private-connection-resource-id $storageaccountid \
  --group-id "file" \
  --connection-name "$storageaccountname-connection" \
  --query "id" -o tsv `

#create private dns zone
privatednszonename="privatelink.file.core.chinacloudapi.cn"

vnetid=`az network vnet show \
  --resource-group $rgname \
  --name $vnetname \
  --query "id" -o tsv`

dnszoneid=`az network private-dns zone create \
  --resource-group $rgname \
  --name $privatednszonename \
  --query "id" -o tsv`
  
az network private-dns link vnet create \
  --resource-group $rgname \
  --zone-name $privatednszonename \
  --name "$vnetname-dnslink" \
  --virtual-network $vnetid \
  --registration-enabled false 

privateendpointnic=`az network private-endpoint show \
  --ids $endpoint \
  --query "networkInterfaces[0].id" -o tsv `

endpointip=`az network nic show \
  --ids $privateendpointnic \
  --query "ipConfigurations[0].privateIpAddress" -o tsv `

az network private-dns record-set a create \
        --resource-group $rgname \
        --zone-name $privatednszonename \
        --name $storageaccountname

az network private-dns record-set a add-record \
        --resource-group $rgname \
        --zone-name $privatednszonename  \
        --record-set-name $storageaccountname \
        --ipv4-address $endpointip

 

  2.執行完畢後,Azure File截圖如下:

  

  

  3.接下來,在子網vm-subnet裏,創建Cent OS VM,截圖略。

  SSH登錄到Azure CentOS VM,執行下面的腳本。具體腳本可以參考Azure Portal截圖:

  

 

  4.VM掛載NFS成功後,截圖如下:

  

  請注意,訪問leiaksnfsstorage02.file.core.chinacloudapi.cn這個地址,是通過Private DNS Zone解析的,是內網IP地址

  

 

  5.我們通過Azure VM,在這個NFS裏手動創建1個文件,如下圖:

 

  6.隨後我們在aks-subnet裏,創建AKS,網絡我這裏設置爲CNI網絡,步驟略。

  7.修改下面的yaml file,主要修改的內容爲下圖紅色部分

  修改完畢後,運行kubectl apply -f yaml。步驟略。

  

  

  8.最後我們通過kubectl exec -it myapp – sh ,通過交互式命令訪問這個pod

  查看pod掛載的路徑叫/var/nfs,可以查看到通過Linux vm創建的文件file1.txt。如下圖:

  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章