Share via


在 Azure Red Hat OpenShift 4 上建立 Azure 檔案儲存體 儲存體Class

在本文中,您將建立適用于 Azure Red Hat OpenShift 4 的 儲存體Class,以使用 Azure 檔案儲存體 動態布建 ReadWriteMany (RWX) 儲存體。 您將了解如何:

  • 設定必要條件並安裝必要的工具
  • 使用 Azure 檔案布建工具建立 Azure Red Hat OpenShift 4 儲存體Class

如果您選擇在本機安裝和使用 CLI,本教學課程會要求您執行 Azure CLI 2.6.0 版或更新版本。 執行 az --version 以尋找版本。 如果您需要安裝或升級,請參閱 安裝 Azure CLI

開始之前

將 Azure Red Hat OpenShift 4 叢集部署至您的訂用帳戶,請參閱 建立 Azure Red Hat OpenShift 4 叢集

設定 Azure 儲存體帳戶

此步驟會在 Azure Red Hat OpenShift (ARO) 叢集的資源群組之外建立資源群組。 此資源群組包含建立 Azure Red Hat OpenShift 動態布建工具的Azure 檔案儲存體共用。

AZURE_FILES_RESOURCE_GROUP=aro_azure_files
LOCATION=eastus

az group create -l $LOCATION -n $AZURE_FILES_RESOURCE_GROUP

AZURE_STORAGE_ACCOUNT_NAME=aroazurefilessa

az storage account create \
	--name $AZURE_STORAGE_ACCOUNT_NAME \
	--resource-group $AZURE_FILES_RESOURCE_GROUP \
	--kind StorageV2 \
	--sku Standard_LRS

設定權限

設定資源群組許可權

ARO 服務主體需要新 Azure 儲存體帳戶資源群組的 'listKeys' 許可權。 指派「參與者」角色以達成此目的。

ARO_RESOURCE_GROUP=aro-rg
CLUSTER=cluster
ARO_SERVICE_PRINCIPAL_ID=$(az aro show -g $ARO_RESOURCE_GROUP -n $CLUSTER --query servicePrincipalProfile.clientId -o tsv)

az role assignment create --role Contributor --scope /subscriptions/mySubscriptionID/resourceGroups/$AZURE_FILES_RESOURCE_GROUP --assignee $ARO_SERVICE_PRINCIPAL_ID

設定 ARO 叢集許可權

OpenShift 永續性磁片區系結器服務帳戶需要能夠讀取秘密。 建立並指派 OpenShift 叢集角色以達成此目的。

ARO_API_SERVER=$(az aro list --query "[?contains(name,'$CLUSTER')].[apiserverProfile.url]" -o tsv)

oc login -u kubeadmin -p $(az aro list-credentials -g $ARO_RESOURCE_GROUP -n $CLUSTER --query=kubeadminPassword -o tsv) $ARO_API_SERVER

oc create clusterrole azure-secret-reader \
	--verb=create,get \
	--resource=secrets

oc adm policy add-cluster-role-to-user azure-secret-reader system:serviceaccount:kube-system:persistent-volume-binder

使用Azure 檔案儲存體布建器建立 儲存體Class

此步驟會建立具有Azure 檔案儲存體布建程式的 儲存體Class。 在 儲存體Class 資訊清單中,需要儲存體帳戶的詳細資料,讓 ARO 叢集知道查看目前資源群組外部的儲存體帳戶。

在儲存體布建期間,會針對掛接認證建立名為 secretName 的秘密。 在多租使用者內容中,強烈建議您明確設定 secretNamespace 的值,否則其他使用者可能會讀取儲存體帳號憑證。

cat << EOF >> azure-storageclass-azure-file.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: azure-file
provisioner: file.csi.azure.com
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=0
  - gid=0
  - mfsymlinks
  - cache=strict
  - actimeo=30
  - noperm
parameters:
  location: $LOCATION
  secretNamespace: kube-system
  skuName: Standard_LRS
  storageAccount: $AZURE_STORAGE_ACCOUNT_NAME
  resourceGroup: $AZURE_FILES_RESOURCE_GROUP
reclaimPolicy: Delete
volumeBindingMode: Immediate
EOF

oc create -f azure-storageclass-azure-file.yaml

Azure 檔案儲存體的掛接選項通常取決於您部署的工作負載,以及應用程式的需求。 特別是針對 Azure 檔案,您應該考慮使用的其他參數。

必要參數:

  • 「mfsymlinks」 將符號連結對應至用戶端可以使用的表單
  • 在用戶端停用許可權檢查的 「noperm」

建議的參數:

  • 如果用戶端已經透過現有的掛接點連線,則為 「nossharesock」 停用重複使用通訊端
  • 「actimeo=30」 (或更新版本) 可增加 CIFS 用戶端快取檔案和目錄屬性的時間
  • 「nobrl」 可停用將位元組範圍鎖定要求傳送至伺服器,以及具有 posix 鎖定挑戰的應用程式

變更預設儲存體Class (選擇性)

ARO 上的預設儲存體Class 稱為受控進階,並使用 azure 磁片布建器。 藉由針對 儲存體Class 資訊清單發出修補程式命令來變更此動作。

oc patch storageclass managed-premium -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'

oc patch storageclass azure-file -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

確認 Azure 檔案儲存體Class (選擇性)

建立新的應用程式,並將儲存體指派給它。

注意

若要使用 httpd-example 範本,您必須部署已啟用提取密碼的 ARO 叢集。 如需詳細資訊,請參閱 取得 Red Hat 提取秘密

oc new-project azfiletest
oc new-app httpd-example

#Wait for the pod to become Ready
curl $(oc get route httpd-example -n azfiletest -o jsonpath={.spec.host})

#If you have set the storage class by default, you can omit the --claim-class parameter
oc set volume dc/httpd-example --add --name=v1 -t pvc --claim-size=1G -m /data --claim-class='azure-file'

#Wait for the new deployment to rollout
export POD=$(oc get pods --field-selector=status.phase==Running -o jsonpath={.items[].metadata.name})
oc exec $POD -- bash -c "echo 'azure file storage' >> /data/test.txt"

oc exec $POD -- bash -c "cat /data/test.txt"
azure file storage

test.txt 檔案也會透過Azure 入口網站中的儲存體總管來顯示。

下一步

在本文中,您已使用 Microsoft Azure 檔案儲存體 和 Azure Red Hat OpenShift 4 建立動態永續性儲存體。 您已了解如何︰

  • 建立儲存體帳戶
  • 使用 Azure 檔案儲存體 布建器在 Azure Red Hat OpenShift 4 叢集上設定 儲存體Class

請前往下一篇文章,以瞭解 Azure Red Hat OpenShift 4 支援的資源。