建立磁碟區集區或佈建磁碟區之前,您必須使用 Private Service Connect (PSC) 設定虛擬私有雲 (VPC) 網路、啟用必要 API,並授予適當的 IAM 角色。
建立專案並啟用 API
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Filestore APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Filestore APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.
必要的角色
如要取得設定 Filestore 代理程式磁碟區所需的權限,請要求管理員在專案中授予您下列 IAM 角色:
-
設定服務連線政策和虛擬私有雲網路:
Compute 網路管理員 (
roles/compute.networkAdmin) -
查看及管理 Filestore 執行個體和相關資源,包括磁碟區集區和代理程式磁碟區:
Cloud Filestore 編輯者 (
roles/file.editor)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
初始化服務代理
如果專案中尚未建立 Filestore 執行個體,請執行下列指令,初始化 Filestore 服務代理程式:
gcloud beta services identity create \
--service=file.googleapis.com \
--project=PROJECT_ID
將 PROJECT_ID 替換為專案 ID。 Google Cloud
將權限授予服務代理
如要設定 Filestore 代理程式磁碟區,請將 Cloud Filestore 編輯者 (roles/file.editor) 角色授予 Filestore 服務代理程式:
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="serviceAccount:service-PROJECT_NUMBER@cloud-filer.iam.iam.gserviceaccount.com" \
--role="roles/file.editor"
更改下列內容:
PROJECT_ID:專案的 ID。 Google CloudPROJECT_NUMBER:您Google Cloud 專案的專案編號。
設定 Private Service Connect 網路
Filestore 代理程式磁碟區會使用 Private Service Connect,將代管式儲存空間基礎架構直接連線至您的虛擬私有雲網路。Private Service Connect 可確保私密、高頻寬和低延遲的通訊,不必使用公開 IP 位址或虛擬私有雲網路對等互連設定。
如要建立服務連線政策,請執行下列指令:
gcloud network-connectivity service-connection-policies create POLICY_NAME \
--project=PROJECT_ID \
--region=REGION \
--network=projects/PROJECT_ID/global/networks/VPC_NETWORK \
--subnets=SUBNET_NAME \
--service-class=google-cloud-filestore
更改下列內容:
POLICY_NAME:服務連線政策的名稱,例如filestore-agent-psc-policy。PROJECT_ID:專案的 ID。 Google CloudREGION:磁碟區集區和工作負載所在的區域,例如us-central1。VPC_NETWORK:現有虛擬私有雲網路的名稱。SUBNET_NAME:指定區域中的一般 VPC 子網路名稱,系統會在此分配 Private Service Connect 端點 IP 位址。舉例來說,預設子網路的--purpose標記可設為PRIVATE。
建立磁碟區集區和 StorageClass
磁碟區集區會為代理程式磁碟區提供共用儲存空間容量和 IOPS。如要從 GKE 的磁碟區集區動態佈建磁碟區,請建立磁碟區集區,然後定義參照該集區的 Kubernetes StorageClass。
建立磁碟區集區
如要建立範例磁碟區集區,請向 volumePools.create 端點傳送 HTTP POST 要求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d '{
"description": "Sample volume pool for agent volumes",
"network": "projects/PROJECT_ID/global/networks/VPC_NETWORK",
"defaultVolumeQuotaMib": 2048,
}' \
"https://file.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/volumePools?volumePoolId=VOLUME_POOL_ID"
更改下列內容:
PROJECT_ID:專案的 ID。 Google CloudVPC_NETWORK:啟用 PSC 的虛擬私有雲網路名稱。LOCATION:磁碟區集區的部署區域,例如us-central1。VOLUME_POOL_ID:磁碟區集區的 ID,例如my-volume-pool。
詳情請參閱「建立及管理磁碟區集區」。
建立 StorageClass
建立名為 volume-pool-sc.yaml 的 StorageClass 資訊清單,其中會參照您的磁碟區集區:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: volume-pool-sc
provisioner: filestore.csi.storage.gke.io
volumeBindingMode: Immediate
reclaimPolicy: Delete
allowVolumeExpansion: true
parameters:
volume-pool: "projects/<var>PROJECT_ID</var>/locations/<var>LOCATION</var>/volumePools/<var>VOLUME_POOL_ID</var>"
更改下列內容:
PROJECT_ID:專案的 ID。 Google CloudLOCATION:磁碟區集區的部署區域。VOLUME_POOL_ID:磁碟區集區的 ID。
如果您現有的 GKE 叢集已安裝 Filestore CSI 驅動程式,請套用 StorageClass:
kubectl apply -f volume-pool-sc.yaml
否則,請在為 Filestore 代理程式磁碟區設定 GKE 環境中設定叢集後,再套用這個資訊清單。