5.6. Google Compute Platform Filestore CSI Driver Operator
5.6.1. 概述
OpenShift Dedicated 可以使用 Google Compute Platform (GCP)文件存储存储的 Container Storage Interface (CSI)驱动程序置备持久性卷(PV)。
在使用 CSI Operator 和驱动程序时,建议先熟悉 持久性存储和配置 CSI 卷。
要创建挂载到 GCP Filestore Storage 资产中的 CSI 置备 PV,您可以在 openshift-cluster-csi-drivers
命名空间中安装 GCP Filestore CSI Driver Operator 和 GCP Filestore CSI 驱动程序。
- GCP Filestore CSI Driver Operator 默认不提供存储类,但如果需要可以创建一个。GCP Filestore CSI Driver Operator 支持动态卷置备,方法是允许按需创建存储卷,使集群管理员无需预置备存储。
- GCP Filestore CSI 驱动程序允许您创建并挂载 GCP Filestore PV。
OpenShift Dedicated GCP Filestore 支持 Workload Identity。这允许用户使用联邦身份而不是服务帐户密钥访问 Google Cloud 资源。在安装过程中,必须全局启用 GCP Workload Identity,然后为 GCP Filestore CSI Driver Operator 配置。如需更多信息,请参阅安装 GCP Filestore CSI Driver Operator。
5.6.2. 关于 CSI
在过去,存储厂商一般会把存储驱动作为 Kubernetes 的一个部分提供。随着容器存储接口 (CSI) 的实现,第三方供应商可以使用标准接口来提供存储插件,而无需更改核心 Kubernetes 代码。
CSI Operators 为 OpenShift Dedicated 用户提供了存储选项,如卷快照,它无法通过 in-tree 卷插件实现。
5.6.3. 安装 GCP Filestore CSI Driver Operator
5.6.3.1. 准备使用 Workload Identity 安装 GCP Filestore CSI Driver Operator
如果您计划在 Google Compute Platform Filestore 中使用 GCP Workload Identity,则必须获取在安装 GCP Filestore Container Storage Interface (CSI) Driver Operator 过程中要使用的某些参数。
先决条件
- 使用具有 cluster-admin 角色的用户访问集群。
流程
准备使用 Workload Identity 安装 GCP Filestore CSI Driver Operator:
获取项目号:
运行以下命令来获取项目 ID:
$ export PROJECT_ID=$(oc get infrastructure/cluster -o jsonpath='{.status.platformStatus.gcp.projectID}')
运行以下命令,使用项目 ID 获取项目号:
$ gcloud projects describe $PROJECT_ID --format="value(projectNumber)"
查找身份池 ID 和供应商 ID:
在集群安装过程中,这些资源的名称会提供给 Cloud Credential Operator 实用程序(
ccoctl
),带有-name 参数
。请参阅"使用 Cloud Credential Operator 实用程序创建 GCP 资源"。为 GCP Filestore Operator 创建 Workload Identity 资源:
使用以下示例文件创建一个
CredentialsRequest
文件:凭证请求 YAML 文件示例
apiVersion: cloudcredential.openshift.io/v1 kind: CredentialsRequest metadata: name: openshift-gcp-filestore-csi-driver-operator namespace: openshift-cloud-credential-operator annotations: include.release.openshift.io/self-managed-high-availability: "true" include.release.openshift.io/single-node-developer: "true" spec: serviceAccountNames: - gcp-filestore-csi-driver-operator - gcp-filestore-csi-driver-controller-sa secretRef: name: gcp-filestore-cloud-credentials namespace: openshift-cluster-csi-drivers providerSpec: apiVersion: cloudcredential.openshift.io/v1 kind: GCPProviderSpec predefinedRoles: - roles/file.editor - roles/resourcemanager.tagUser skipServiceCheck: true
运行以下命令,使用
CredentialsRequest
文件创建 GCP 服务帐户:$ ./ccoctl gcp create-service-accounts --name=<filestore-service-account> \1 --workload-identity-pool=<workload-identity-pool> \2 --workload-identity-provider=<workload-identity-provider> \3 --project=<project-id> \4 --credentials-requests-dir=/tmp/credreq 5
输出示例
2025/02/10 17:47:39 Credentials loaded from gcloud CLI defaults 2025/02/10 17:47:42 IAM service account filestore-service-account-openshift-gcp-filestore-csi-driver-operator created 2025/02/10 17:47:44 Unable to add predefined roles to IAM service account, retrying... 2025/02/10 17:47:59 Updated policy bindings for IAM service account filestore-service-account-openshift-gcp-filestore-csi-driver-operator 2025/02/10 17:47:59 Saved credentials configuration to: /tmp/install-dir/ 1 openshift-cluster-csi-drivers-gcp-filestore-cloud-credentials-credentials.yaml
- 1
- 当前目录。
运行以下命令,查找新创建的服务帐户电子邮件:
$ cat /tmp/install-dir/manifests/openshift-cluster-csi-drivers-gcp-filestore-cloud-credentials-credentials.yaml | yq '.data["service_account.json"]' | base64 -d | jq '.service_account_impersonation_url'
输出示例
https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/filestore-se-openshift-g-ch8cm@openshift-gce-devel.iam.gserviceaccount.com:generateAccessToken
在这个示例中,服务帐户电子邮件是
filestore-se-openshift-g-ch8cm@openshift-gce-devel.iam.gserviceaccount.com
。
结果
现在,您具有安装 GCP Filestore CSI Driver Operator 所需的以下参数:
- 项目号 - 从第 1 步开始
- 池 ID - 在第 2 步中
- 供应商 ID - 从第 2 步中
- 服务帐户电子邮件 - 从第 3 步开始
5.6.3.2. 安装 GCP Filestore CSI Driver Operator
默认情况下,Google Compute Platform (GCP) Filestore Container Storage Interface (CSI) Driver Operator 不会在 OpenShift Dedicated 中安装。使用以下步骤在集群中安装 GCP Filestore CSI Driver Operator。
先决条件
- 访问 OpenShift Dedicated Web 控制台。
- 如果使用 GCP Workload Identity,则需要某些 GCP Workload Identity 参数。请参阅上一节 准备使用 Workload Identity 安装 GCP Filestore CSI Driver Operator。
流程
从 web 控制台安装 GCP Filestore CSI Driver Operator:
- 登录 OpenShift Cluster Manager。
- 选择集群。
- 点 Open console,并使用您的凭证登录。
运行以下命令,在 GCE 项目中启用 Filestore API:
$ gcloud services enable file.googleapis.com --project <my_gce_project> 1
- 1
- 将
<my_gce_project>
替换为您的 Google Cloud 项目。
您还可以使用 Google Cloud web 控制台进行此操作。
安装 GCP Filestore CSI Operator:
-
点 Operators
OperatorHub。 - 通过在过滤器框中输入 GCP Filestore 来查找 GCP Filestore CSI Operator。
- 点 GCP Filestore CSI Driver Operator 按钮。
- 在 GCP Filestore CSI Driver Operator 页面中,点 Install。
在 Install Operator 页面中,确保:
- 选择 All namespaces on the cluster (default)。
安装的命名空间 被设置为 openshift-cluster-csi-drivers。
如果使用 GCP Workload Identity,请为从 准备安装带有 Workload Identity 的 GCP Filestore CSI Driver Operator 中的步骤中获取的以下字段输入值 :
- GCP 项目号
- GCP 池 ID
- GCP 供应商 ID
- GCP 服务帐户电子邮件
点 Install。
安装完成后,GCP Filestore CSI Operator 会在 web 控制台的 Installed Operators 部分列出。
-
点 Operators
安装 GCP Filestore CSI 驱动程序:
-
点 Administration
CustomResourceDefinitions ClusterCSIDriver。 在 Instances 选项卡上,单击 Create ClusterCSIDriver。
使用以下 YAML 文件:
apiVersion: operator.openshift.io/v1 kind: ClusterCSIDriver metadata: name: filestore.csi.storage.gke.io spec: managementState: Managed
- 点 Create。
等待以下 Conditions 变为 "true" 状态:
- GCPFilestoreDriverCredentialsRequestControllerAvailable
- GCPFilestoreDriverNodeServiceControllerAvailable
- GCPFilestoreDriverControllerServiceControllerAvailable
-
点 Administration
5.6.4. 为 GCP Filestore 存储创建存储类
安装 Operator 后,您应该创建一个存储类来动态置备 Google Compute Platform (GCP) 文件存储卷。
先决条件
- 已登陆到正在运行的 OpenShift Dedicated 集群。
流程
创建存储类:
使用以下 YAML 文件示例创建存储类:
YAML 文件示例
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: filestore-csi provisioner: filestore.csi.storage.gke.io parameters: connect-mode: DIRECT_PEERING 1 network: network-name 2 allowVolumeExpansion: true volumeBindingMode: WaitForFirstConsumer
指定在其中创建 Filestore 实例的 VPC 网络的名称。
建议您指定应在其中创建 Filestore 实例的 VPC 网络。如果没有指定 VPC 网络,Container Storage Interface (CSI) 驱动程序会尝试在项目的默认 VPC 网络中创建实例。
在 IPI 安装中,VPC 网络名称通常是带有后缀 "-network" 的集群名称。但是,在 UPI 安装中,VPC 网络名称可以是用户选择的任何值。
对于一个共享的 VPC (
connect-mode
=PRIVATE_SERVICE_ACCESS
),网络需要是一个完整的 VPC 名。例如:projects/shared-vpc-name/global/networks/gcp-filestore-network
。您可以使用以下命令检查
MachineSets
对象来查找 VPC 网络名称:$ oc -n openshift-machine-api get machinesets -o yaml | grep "network:" - network: gcp-filestore-network (...)
在本例中,这个集群中的 VPC 网络名称为 "gcp-filestore-network"。
5.6.5. 销毁集群和 GCP 文件存储
通常,如果您销毁集群,OpenShift Dedicated 安装程序会删除属于该集群的所有云资源。但是,由于 Google Compute Platform (GCP) Filestore 资源的特殊性质,自动清理过程可能不会在一些罕见的情况下删除所有它们。
因此,红帽建议您验证所有由集群拥有的 Filestore 资源都由卸载过程删除。
流程
确保所有 GCP Filestore PVC 都已被删除:
- 使用 GUI 或 CLI 访问 Google Cloud 帐户。
搜索任何带有
kubernetes-io-cluster-${CLUSTER_ID}=owned
标签的资源。由于集群 ID 对已删除集群是唯一的,因此不应具有具有该集群 ID 的任何剩余资源。
- 在不太可能的情况下,删除剩余的资源。