为应用程序添加 File Storage for VPC
IBM Cloud® Kubernetes Service 提供可用于供应 File Storage for VPC的预定义存储类。 每个存储类都指定了 File Storage for VPC 的配置类型,包括可用大小、IOPS、文件系统和保留策略。 您还可以根据用例创建自己的存储类。
File Storage for VPC 集群附加组件在 Beta 中可用。
以下限制适用于附加组件测试版。
- 如果群集和 VPC 分属不同的资源组,则在配置文件共享之前,必须创建自己的存储类,并在
resourceGroup
部分提供 VPC 资源组 ID,以及kube-<clusterID>
securityGroupIDs
部分提供安全组 ID。 要检索安全组 ID,请执行以下操作。 有关详细信息,请参阅 创建自己的存储类。 - 4.11 及更高版本的群集引入了新的安全组规则。 这些规则更改意味着您必须先同步安全组,然后才能使用File Storage for VPC。 有关详细信息,请参阅For more information, see 添加File Storage for VPC到应用程序。
- 版本中添加了新的存储类别2.0的附加组件。 您无法再配置使用旧存储类别的新文件共享。 使用较旧存储类别的现有卷可以继续运行,但无法扩展使用较旧类别创建的卷。 有关详细信息,请参阅 迁移到新的存储类别。
- 不支持使用 StorageClassSecrets 不支持创建 PVC。
使用存储类配置特定类型的存储后,就无法更改存储设备的类型或保留策略。 但是,如果要增加存储容量和性能,可以 更改大小 和 IOPS。 要更改存储的类型和保留策略,必须创建一个新的存储实例,并将旧存储实例中的数据复制到新实例中。
决定存储类。 有关更多信息,请参阅 存储类参考。
查看 File Storage for VPC的以下说明和注意事项。
- 确保创建群集的用户拥有 VPC 基础架构服务的阅读器、写入器和操作员权限。
- 如果您计划在文件共享上使用加密,请确保 设置从 VPC 基础设施到 KMS/HPCS 的服务授权。
- 缺省情况下,File Storage for VPC 集群附加组件供应
kube-<clusterID>
安全组中的文件共享。 这意味着 pod 可以跨节点和区域访问文件共享。 - 如果使用基于上下文的限制,请确保配置了网络区域和规则。 有关详细信息,请参阅 使用基于上下文的限制保护虚拟私有云(VPC)基础设施服务。
如果需要以下功能,那么必须 创建自己的存储类。
- 应用程序需要以非 root 用户身份运行。
- 集群与 VPC 和子网位于不同的资源组中。
- 您需要限制对给定节点上或给定区域中的 pod 的文件共享访问。
- 您需要使用 KMS 提供程序 (例如 HPCS 或 Key Protect) 自带 (BYOK) 加密。
- 您需要手动指定 虚拟网络接口(VNI) 的子网或 IP 地址。
4.11 及更高版本中引入了新的安全组规则。 这些规则更改意味着必须先同步安全组,然后才能使用 File Storage for VPC。 如果群集的初始创建版本为 4.11 或更早,请运行以下命令同步安全组设置。
- 获取群集的 ID。
ibmcloud oc cluster ls
- 获取
kube-<clusterID>
安全组的标识。ibmcloud is sg kube-<cluster-id> | grep ID
- 使用上一步中获取的 ID 同步
kube-<clusterID>
安全组。ibmcloud ks security-group sync -c <cluster ID> --security-group <ID>
快速启动 File Storage for VPC
创建持久卷申请 (PVC),为群集动态调配 File Storage for VPC。 动态配置会自动创建匹配的持久卷 (PV),并在账户中订购文件共享。
-
通过运行以下命令来查看预安装的存储类。 有关更多信息,请参阅 存储类参考。
oc get sc | grep vpc-file
-
将以下 YAML 保存到文件中。 此示例通过使用具有千兆字节大小
10Gi
的ibmc-vpc-file-min-iops
存储类来创建名为my-pvc
的声明。apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc # Enter a name for your PVC. spec: accessModes: - ReadWriteMany # The file share can be mounted on multiple nodes and pods. resources: requests: storage: 20Gi # Enter the size of the storage in gigabytes (Gi). storageClassName: ibmc-vpc-file-min-iops # Enter the name of the storage class that you want to use.
-
创建 PVC。
oc apply -f my-pvc.yaml
-
验证 PVC 是否已创建并与 PV 绑定。
oc describe pvc my-pvc
示例输出
Name: my-pvc Namespace: default StorageClass: "" Status: Bound Volume: pvc-0d787071-3a67-11e7-aafc-eef80dd2dea2 Labels: <none> Capacity: 20Gi Access Modes: RWX Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 1m 1m 1 {ibm.io/ibmc-vpc-file 31898035-3011-11e7-a6a4-7a08779efd33 } Normal ProvisioningSucceeded Successfully provisioned volume pvc-0d787071-3a67-11e7-aafc-eef80dd2dea2
-
将以下部署配置保存到名为
deployment.yaml
的文件中,并引用您在上一步中创建的 PVC。apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment labels: app: my-deployment spec: selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: containers: - name: busybox image: busybox:1.28 command: [ "sh", "-c", "sleep 1h" ] volumeMounts: - name: my-vol mountPath: /data/demo # Mount path for the application. volumes: - name: my-vol persistentVolumeClaim: claimName: my-pvc # Your PVC name.
volumeMounts.mountPath
- 在“容器卷安装”部分中,输入在容器内安装卷的目录的绝对路径。 写入挂载路径的数据存储在物理 File Storage for VPC 实例的
root
目录下。 如果要在不同应用程序之间共享音量,可以为每个应用程序指定 音量子路径。 volumeMounts.name
- 在“容器卷安装”部分中,输入要安装到 pod 的卷的名称。
volume.name
- 在“卷”部分中,输入要安装到 pod 的卷的名称。 该名称通常与
volumeMounts.name
. claimName
- 在卷持久卷声明部分中,输入用于绑定要使用的 PV 的 PVC 的名称。
-
创建部署。
oc apply -f deployment.yaml
-
验证 PV 是否已成功安装。
oc describe deployment my-deployment
安装点位于 Volume Mounts 字段中,卷位于 Volumes 字段中。
Containers: Mounts: /data/demo from my-vol (rw) Volumes: my-vol: Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace) ClaimName: my-pvc ReadOnly: false
-
可选: 在 pod 运行后,请尝试 扩展存储卷。
迁移到新的存储类别
- 版本中添加了新的存储类别2.0的附加组件。
- 您无法再配置使用旧存储类别的新文件共享。
- 使用较旧存储类别的现有卷可以继续运行,但无法扩展使用较旧类别创建的卷。
- 如果您需要卷扩展功能,请完成以下步骤将您的应用迁移到较新的存储类。
- 如果您不需要卷扩展功能,则无需迁移,并且您的 PVC 将继续正常运行。
- 以下步骤涵盖手动迁移。 如果您使用 PX 备份或 Velero 等备份服务,则可以使用这些服务将您的应用程序备份和恢复到新的存储类。
-
找到要迁移的 PVC,并记下 PVC 名称和关联的 PV 名称。
oc get pvc
-
缩小使用 PVC 的应用程序。
oc scale deployment DEPLOYMENT --replicas 0
-
编辑你的应用正在使用的 PV 对象,将回收策略更改为
Retain
和存储类别ibmc-vpc-file-min-iops
。kubectl edit pv PV
spec: accessModes: - ReadWriteMany capacity: storage: 20Gi claimRef: apiVersion: v1 kind: PersistentVolumeClaim name: <pvc-name> namespace: default ... persistentVolumeReclaimPolicy: Retain # Change delete to retain storageClassName: ibmc-vpc-file-min-iops # Enter a new storage class volumeMode: Filesystem
-
删除现有的 PVC 对象。
kubectl delete pvc PVC
-
再次编辑 PV 并删除
claimRef
部分。kubectl edit pv PV
spec: accessModes: - ReadWriteMany capacity: storage: 20Gi #claimRef: #apiVersion: v1 #kind: PersistentVolumeClaim #name: <pvc-name> #namespace: default #resourceVersion: "381270" #uid: 4042f319-1233-4187-8549-8249a840a8dd
-
创建一个与之前的 PVC 具有相同名称和大小的 PVC。 应该对所有受影响的 PVC 逐一执行此操作。
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: <pvc-name> spec: accessModes: - ReadWriteMany resources: requests: storage: <size>Gi storageClassName: ibmc-vpc-file-min-iops
-
扩大使用 PVC 的应用程序。
k scale deployment DEPLOYMENT --replicas x
-
要继续使用卷扩展,请参阅 设置卷扩展。
设置卷扩展
要供应支持扩展的卷,必须使用将 allowVolumeExpansion
设置为 true
的存储类。
File Storage for VPC 集群附加组件支持以联机和脱机方式进行扩展。 但是,只能在给定的 File Storage for VPC 概要文件的大小和 IOP 范围 中进行扩展。
版本中引入了新的存储类别2.0。 对于使用早期版本附加组件的存储类的共享,卷扩展不起作用。
准备工作
-
要使用卷扩展,请确保 将您的附加组件更新至至少版本2.0。
-
如果你没有正在运行的应用程序,请先部署 快速入门示例 PVC 和部署。
扩展已安装的卷
-
在应用程序 pod 安装 PVC 后,可以通过编辑 PVC 中
spec.resources.requests.storage
字段的值来扩展卷。 要扩展卷,请编辑 PVC 并增大spec.resources.requests.storage
字段中的值。kubectl edit pvc my-pvc
spec: accessModes: - ReadWriteMany resources: requests: storage: 50Gi
-
保存并关闭 PVC。 等待几分钟以扩展卷。
-
验证音量是否已扩展。
kubectl get pvc
示例输出
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE my-pvc Bound pvc-25b6912e-75bf-41ca-b6b2-567fa4f9d245 50Gi RWX ibmc-vpc-file-min-iops 3m31s
将现有文件存储器附加到应用程序
创建持久卷申请 (PVC),为群集静态配置 File Storage for VPC。 静态供应允许集群管理员使现有存储设备可供集群使用。
-
获取集群标识。
ibmcloud ks cluster ls
-
获取
kube-<clusterID>
安全组的 ID。ibmcloud is sg kube-<cluster-id> | grep ID
-
创建文件共享。 有关更多信息,请参阅 创建文件共享和安装目标。
ibmcloud is share-create --name my-file-share --zone us-south-2 --profile dp2 --size 1000 --iops 1000
-
创建共享挂载目标,并指定
kube-<clusterID>
安全组 ID,该 ID 是您之前在--vni-sgs
选项中获取的。ibmcloud is share-mount-target-create my-file-share --subnet my-subnet --name NAME --vni-name my-share-vni-1 --vni-sgs kube-<cluster-id> --resource-group-name Default --vpc ID
-
在创建持久卷 (PV) 之前,请检索有关文件共享的详细信息。
ibmcloud is shares
-
获取共享的详细信息。 记下安装目标。
ibmcloud is share SHARE-ID
示例命令。
ibmcloud is share r134-bad98878-1f63-45d2-a3fd-60447094c2e6
示例输出
ID r134-bad98878-1f63-45d2-a3fd-60447094c2e6 Name pvc-e7e005a9-e96b-41ad-9d6e-74650a9110a0 CRN crn:v1:staging:public:is:us-south-1:a/77f2bceddaeb577dcaddb4073fe82c1c::share:r134-bad98878-1f63-45d2-a3fd-60447094c2e6 Lifecycle state stable Access control mode security_group Zone us-south-1 Profile dp2 Size(GB) 10 IOPS 100 User Tags clusterid:cpjao3l20dl78jadqkd0,namespace:default,provisioner:vpc.file.csi.ibm.io,pv:pvc-e7e005a9-e96b-41ad-9d6e-74650a9110a0,pvc:pv-file,reclaimpolicy:delete,storageclass:custom-eni Encryption provider_managed Mount Targets ID Name r134-aa2aabb8-f616-47be-886b-99220852b728 pvc-e7e005a9-e96b-41ad-9d6e-74650a9110a0 Resource group ID Name 300b9469ee8676f9a038ecdf408c1a9d Default Created 2024-06-11T19:55:11+05:30 Replication role none Replication status none Replication status reasons Status code Status message
-
获取
nfsServerPath
(也称为Mount Path
)。ibmcloud is share-mount-target SHARE-ID SHARE-TARGET-ID
示例命令。
ibmcloud is share-mount-target r134-bad98878-1f63-45d2-a3fd-60447094c2e6 r134-aa2aabb8-f616-47be-886b-99220852b728
示例输出
ID r134-aa2aabb8-f616-47be-886b-99220852b728 Name pvc-e7e005a9-e96b-41ad-9d6e-74650a9110a0 VPC ID Name r134-f05922d4-d8ab-4f64-9a3d-82664b303bc1 vpc-public Access control mode security_group Resource type share_mount_target Virtual network interface ID Name 0716-6407fb4b-e962-49c4-8556-dc94f4574b4b defective-chloride-huffy-gladly Lifecycle state stable Mount path 10.240.0.23:/89d8a454_f552_42bf_8374_4d31481edf4d Transit Encryption none Created 2024-06-11T19:55:12+05:30
-
创建名为
static-file-share.yaml
的 PV 配置文件,该文件引用您的文件共享。apiVersion: v1 kind: PersistentVolume metadata: name: static-file-share spec: mountOptions: - hard - nfsvers=4.1 - sec=sys accessModes: - ReadWriteMany capacity: storage: 10Gi csi: volumeAttributes: nfsServerPath: NFS-SERVER-PATH isEITEnabled: true # The default is false driver: vpc.file.csi.ibm.io volumeHandle: FILE-SHARE-ID#SHARE-TARGET-ID
-
创建 PV。
oc apply -f static-file-share.yaml
-
创建 PVC。
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-static spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi storageClassName: "" #Leave the storage class blank.
-
创建 PVC 以绑定 PV。
oc apply -f pvc-static.yaml
-
创建部署文件名
testpod.yaml
,将文件共享附加到应用程序 pod。apiVersion: apps/v1 kind: Deployment metadata: name: testpod labels: app: testpod spec: replicas: 1 selector: matchLabels: app: testpod template: metadata: labels: app: testpod spec: containers: - image: IMAGE # The name of the container image that you want to use. name: CONTAINER-NAME # The name of the container that you want to deploy to your cluster. volumeMounts: - mountPath: /myvol name: pvc-name volumes: - name: pvc-name persistentVolumeClaim: claimName: pvc-static # The name of the PVC that you created earlier
spec.containers.volumeMounts.mountPath
- 输入在容器中安装卷的目录的绝对路径。 写入挂载路径的数据存储在物理 File Storage for VPC 实例的
root
目录下。 如果要在不同应用程序之间共享音量,可以为每个应用程序指定 音量子路径。 volumeMounts.name
- 输入要安装到 pod 的卷的名称。
volume.name
- 输入要安装到 pod 的卷的名称。 该名称通常与
volumeMounts.name
. volumes.persistentVolumeClaim.claimName
- 输入绑定要使用的 PV 的 PVC 名称。
-
创建部署。
oc apply -f testpod.yaml
创建您自己的存储类
使用 File Storage for VPC 实例的首选设置创建您自己的定制存储类。 以下示例使用 dp2
概要文件。
如果群集和 VPC 不在同一个资源组中,则必须在 resourceGroup
部分指定 VPC 资源组 ID,并在 securityGroupIDs
部分指定 kube-<clusterID>
安全组 ID。 您可以通过运行 ibmcloud is sg kube-<cluster-id> | grep ID
查找 kube-<clusterID>
安全组的 ID。
-
创建存储类配置文件。
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: ibmc-vpc-file-custom-sc labels: app.kubernetes.io/name: ibm-vpc-file-csi-driver annotations: version: v2.0 provisioner: vpc.file.csi.ibm.io mountOptions: - hard - nfsvers=4.1 - sec=sys parameters: profile: "dp2" billingType: "hourly" # hourly or monthly encrypted: "false" encryptionKey: "" # If encrypted is true, then a user must specify the CRK-CRN. resourceGroup: "" # Resource group ID. By default, the resource group of the cluster will be used from storage-secrete-store secret. isENIEnabled: "true" # VPC File Share VNI feature will be used by all PVCs created with this storage class. securityGroupIDs: "" # By default cluster security group i.e kube-<clusterID> will be used. User can provide their own comma separated SGs. subnetID: "" # User can provide subnetID in which the VNI will be created. Zone and region are mandatory for this. If not provided CSI driver will use the subnetID available in the cluster's VPC zone. region: "" # VPC CSI driver will select a region from cluster node's topology. The user can override this default. zone: "" # VPC CSI driver will select a region from cluster node's topology. The user can override this default. primaryIPID: "" # Existing ID of reserved IP from the same subnet as the file share zone. Zone and region are mandatory for this. SubnetID is not mandatory for this. primaryIPAddress: "" # IPAddress for VNI to be created in the subnet of the zone. Zone, region and subnetID are mandatory for this. tags: "" # User can add a list of tags "a, b, c" that will be used at the time of provisioning file share, by default CSI driver has its own tags. uid: "0" # The initial user identifier for the file share, by default its root. gid: "0" # The initial group identifier for the file share, by default its root. classVersion: "1" reclaimPolicy: "Delete" allowVolumeExpansion: true
-
在集群中创建定制存储类。
oc apply -f custom-storageclass.yaml
-
验证存储类是否在集群中可用。
oc get sc
示例输出
ibmc-vpc-file-custom-sc vpc.file.csi.ibm.io
设置默认存储类别
- 更改默认存储类别仅适用于附加组件 2.0 或更高版本。
- 您可以将默认存储类设置为预安装的 File Storage for VPC 类之一或您自己的自定义存储类。 如果使用自定义存储类,请确保将供应器设置为
vpc.file.csi.ibm.io
。 - 如果在群集中将多个存储类设置为默认存储类,则可以使用任何一个默认存储类。 作为最佳实践,为确保使用正确的存储类,在设置新的默认类之前,请删除群集中任何现有的默认存储类。
-
编辑
addon-vpc-file-csi-driver-configmap
configmap 并在SET_DEFAULT_STORAGE_CLASS
参数中指定存储类名称。oc edit cm addon-vpc-file-csi-driver-configmap -n kube-system
示例输出
SET_DEFAULT_STORAGE_CLASS: "ibmc-vpc-file-eit"
-
通过描述
file-csi-driver-status
configmap 验证默认设置是否正确。oc describe cm file-csi-driver-status -n kube-system
示例输出。
events: ---- - event: EnableVPCFileCSIDriver description: 'VPC File CSI Driver enable successful, DriverVersion: v2.0.6' timestamp: "2024-09-20 12:01:02" - event: Change default storage class request description: Successfully set 'ibmc-vpc-file-eit' as default storage class timestamp: "2024-09-20 12:01:36"
部署以非 root 用户身份运行的应用程序
-
创建您自己的存储类,并指定要用于应用程序的组标识或用户标识。
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: ibmc-vpc-file-custom-sc labels: app.kubernetes.io/name: ibm-vpc-file-csi-driver annotations: version: v2.0 provisioner: vpc.file.csi.ibm.io mountOptions: - hard - nfsvers=4.1 - sec=sys parameters: profile: "dp2" iops: "100" billingType: "hourly" # hourly or monthly encrypted: "false" uid: "3000" # The initial user identifier for the file share. gid: "1000" # The initial group identifier for the file share. classVersion: "1" reclaimPolicy: "Delete" allowVolumeExpansion: true
-
将以下 YAML 保存到名为
my-pvc.yaml
的文件中。apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi storageClassName: ibmc-vpc-file-custom-sc
-
创建 PVC。
oc apply -f my-pvc.yaml
-
创建用于安装 PVC 的 pod。
apiVersion: v1 kind: Pod metadata: name: security-context-demo spec: securityContext: runAsUser: 3000 runAsGroup: 1000 volumes: - name: sec-ctx-vol emptyDir: {} containers: - name: sec-ctx-demo image: busybox:1.28 command: [ "sh", "-c", "sleep 1h" ] volumeMounts: - name: sec-ctx-vol mountPath: /data/demo securityContext: allowPrivilegeEscalation: false persistentVolumeClaim: claimName: my-pvc
-
确认 pod 正在运行。
oc get pods
为File Storage for VPC设置 KMS 加密
使用密钥管理服务 (KMS) 提供商(如 IBM® Key Protect )创建私人根密钥,并在 File Storage for VPC 实例中使用该密钥对写入存储的数据进行加密。 创建私人根密钥后,用根密钥创建自己的存储类或 Kubernetes 密钥,然后使用该存储类或密钥配置 File Storage for VPC 实例。
-
创建要使用的 KMS 提供程序的实例。
-
在 KMS 实例中创建一个根密钥。
- Key Protect 根密钥。
- Hyper Protect Crypto Services 根密钥。 缺省情况下,会创建没有到期日期的根密钥。
-
设置服务对服务授权。 授权 File Storage for VPC 访问 IBM® Key Protect。 确保至少让 File Storage for VPC 拥有
Reader
访问 KMS 实例的权限。 -
创建自定义存储类并指定 KMS 详细信息。
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: custom-sc-encrypted labels: app.kubernetes.io/name: ibm-vpc-file-csi-driver annotations: version: v2.0 provisioner: vpc.file.csi.ibm.io mountOptions: - hard - nfsvers=4.1 - sec=sys parameters: profile: "dp2" billingType: "hourly" # hourly or monthly encrypted: "true" encryptionKey: "" # Specify the root key CRN. resourceGroup: "" # Resource group ID. By default, the resource group of the cluster will be used from storage-secrete-store secret. isENIEnabled: "true" # VPC File Share VNI feature will be used by all PVCs created with this storage class. securityGroupIDs: "" # By default cluster security group i.e kube-<clusterID> will be used. User can provide their own comma separated SGs. subnetID: "" # User can provide subnetID in which the VNI will be created. Zone and region are mandatory for this. If not provided CSI driver will use the subnetID available in the cluster's VPC zone. region: "" # VPC CSI driver will select a region from cluster node's topology. The user can override this default. zone: "" # VPC CSI driver will select a region from cluster node's topology. The user can override this default. primaryIPID: "" # Existing ID of reserved IP from the same subnet as the file share zone. Zone and region are mandatory for this. SubnetID is not mandatory for this. primaryIPAddress: "" # IPAddress for VNI to be created in the subnet of the zone. Zone, region and subnetID are mandatory for this. tags: "" # User can add a list of tags "a, b, c" that will be used at the time of provisioning file share, by default CSI driver has its own tags. uid: "0" # The initial user identifier for the file share, by default its root. gid: "0" # The initial group identifier for the file share, by default its root. classVersion: "1" reclaimPolicy: "Delete" allowVolumeExpansion: true
-
创建存储类。
oc apply -f encrypted-class.yaml
-
将以下 YAML 保存到名为
my-pvc.yaml
的文件中。apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi storageClassName: custom-sc-encrypted
-
创建 PVC。
oc apply -f my-pvc.yaml
-
将以下部署配置保存到名为
deployment.yaml
的文件中,并引用您在上一步中创建的 PVC。apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment labels: app: my-deployment spec: selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: containers: - name: busybox image: busybox:1.28 command: [ "sh", "-c", "sleep 1h" ] volumeMounts: - name: my-vol mountPath: /data/demo # Mount path for the application. volumes: - name: my-vol persistentVolumeClaim: claimName: my-pvc # Your PVC name.
volumeMounts.mountPath
- 在“容器卷安装”部分中,输入在容器内安装卷的目录的绝对路径。 写入挂载路径的数据存储在物理 File Storage for VPC 实例的
root
目录下。 如果要在不同应用程序之间共享音量,可以为每个应用程序指定 音量子路径。 volumeMounts.name
- 在“容器卷安装”部分中,输入要安装到 pod 的卷的名称。
volume.name
- 在“卷”部分中,输入要安装到 pod 的卷的名称。 通常情况下,该名称与
volumeMounts.name
相同。
-
创建部署。
oc apply -f deployment.yaml
设置传输中加密 (EIT)
查看以下有关经济过渡期的信息。
- 默认情况下,文件共享 静态加密 和IBM-管理加密。
- 如果您选择使用传输中加密,则需要在性能和增强的安全性之间平衡您的要求。 由于需要在端点加密和解密数据,因此对传输中的数据进行加密可能会对性能产生影响。
- EIT 不适用于默认安全集群,需要您禁用集群中的出站流量保护4.15然后。
- EIT 适用于4.16及更高版本的群集。
- 有关传输中加密的更多信息,请参阅 VPC 传输加密。
完成以下步骤,为文件共享设置传输加密 (EIT)Red Hat OpenShift on IBM Cloud簇。 启用 EIT 会在您的工作节点上安装所需的包。
-
记下您想要启用 EIT 的集群中的工作池。
-
编辑
addon-vpc-file-csi-driver-configmap
。oc edit cm addon-vpc-file-csi-driver-configmap -n kube-system
-
在 configmap 中,设置
ENABLE_EIT:true
并将要启用 EIT 的工作池添加到WORKER_POOLS_WITH_EIT
。 例如:"wp1, wp2"
。apiVersion: v1 data: EIT_ENABLED_WORKER_POOLS: "wp1,wp2" # Specify the worker pools where you want to enable EIT. If this field is blank, EIT is not enabled on any worker pools. ENABLE_EIT: "true" PACKAGE_DEPLOYER_VERSION: v1.0.0 kind: ConfigMap metadata: annotations: version: v2.0.1 creationTimestamp: "2024-06-18T09:45:48Z" labels: app.kubernetes.io/name: ibm-vpc-file-csi-driver name: addon-vpc-file-csi-driver-configmap namespace: kube-system ownerReferences: - apiVersion: csi.drivers.ibmcloud.io/v1 blockOwnerDeletion: true controller: true kind: VPCFileCSIDriver name: ibm-vpc-file-csi-driver uid: d3c8bbcd-24fa-4203-9352-4ab7aa72a055 resourceVersion: "1251777" uid: 5c9d6679-4135-458b-800d-217b34d27c75
-
启用 EIT 后,保存并关闭配置图。
-
要验证 EIT 是否已启用,请查看
file-csi-driver-status
配置图。oc describe cm file-csi-driver-status -n kube-system
示例输出
apiVersion: v1 data: EIT_ENABLED_WORKER_NODES: | default: - 10.240.0.10 - 10.240.0.8 PACKAGE_DEPLOYER_VERSION: v1.0.0 events: | - event: EnableVPCFileCSIDriver description: 'VPC File CSI Driver enable successful, DriverVersion: v2.0.3' timestamp: "2024-06-13 09:17:07" - event: EnableEITRequest description: 'Request received to enableEIT, workerPools: , check the file-csi-driver-status configmap for eit installation status on each node of each workerpool.' timestamp: "2024-06-13 09:17:31" - event: 'Enabling EIT on host: 10.240.0.10' description: 'Package installation successful on host: 10.240.0.10, workerpool: wp1' timestamp: "2024-06-13 09:17:48" - event: 'Enabling EIT on host: 10.240.0.8' description: 'Package installation successful on host: 10.240.0.8, workerpool: wp2' timestamp: "2024-06-13 09:17:48"
-
选择支持 EIT 的预安装存储类或创建您自己的存储类。
- 使用以下任一方式创建 PVC
ibmc-vpc-file-eit
存储类。 - 创建自己的存储类并设置
isEITenabled
参数true
。
- 使用以下任一方式创建 PVC
-
创建一个引用您选择的存储类的 PVC,然后部署一个使用您的 PVC 的应用程序。
限制工作程序池,区域或工作程序节点的文件共享访问权
File Storage for VPC 集群附加组件的缺省行为是任何节点上的 pod 都可以访问文件共享。 您还可以对 pod 访问文件共享的方式应用更精细的控制。 例如,您可以将文件共享访问权仅限于特定节点上的特定区域中特定工作程序池上的 pod。 请查看以下场景,以了解如何配置对文件共享的 pod 访问。
创建 PVC 时,会为每个 PVC 创建一个文件共享目标,并在区域中的该子网上保留一个 VNI IP。 这意味着 VPC 文件存储器的最大 PVC 数取决于该子网上的可用 IP 地址。
如果使用以下 VNI 功能来限制对文件共享的 pod 访问,那么应用程序可能不具有高可用性。
准备工作
要按节点,区域或资源组限制文件共享访问,必须首先创建定制 VPC 安全组。
-
列出集群并记下要在其中部署文件存储器的集群标识。
ibmcloud ks cluster ls
-
了解您的员工库详情。
ibmcloud ks worker-pool ls --cluster <cluster>
-
获取子网详细信息。
ibmcloud ks worker-pool get <worker-pool> --cluster <cluster> | grep -A 3 Subnets
-
获取子网 CIDR。 对每个子网重复此步骤。 稍后您将使用此 CIDR 范围。
ibmcloud is subnet <subnet-id> | grep "IPv4 CIDR"
-
列出安全组并记下集群的标识
kube-<clusterID>
安全组。 稍后在添加安全组规则时需要安全组标识。ibmcloud is sg
示例输出
ID Name Rules Targets VPC Resource group r006-4aaec88f-4986-4b7c-a737-401f7fef1555 kube-clusterID 15 0 my-vpc default
-
在与集群相同的 VPC 中创建定制安全组。 您可以使用此安全组通过添加安全组规则来控制对文件共享的访问。
ibmcloud is security-group-create my-custom-security-group VPC-ID
-
创建您自己的存储类,并输入先前创建的定制安全组的标识。 从此存储类创建的所有 PVC 都在您的定制安全组中。
-
创建使用您自己的存储类的 PVC。
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-custom-vni spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi storageClassName: "" # For example: my-custom-storage-class
-
PV 绑定到 PVC 后,获取 PV 详细信息并记下
nfsServerPath
值以查找 VNI IP 地址。kubectl get pv pvc-XXXX -o yaml | grep nfsServerPath
示例输出
nfsServerPath: XXX.XX.XX.XXX:/XX # VNI IP address
在一个工作程序节点上限制对 pod 的文件共享访问
-
确保您已 完成先决条件。
-
将以下规则添加到先前创建的定制安全组。
ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.240.0.20 # Worker node IP
-
在
kube-clusterID
安全组中添加以下规则。ibmcloud is sg-rulec kube-<cluster-id> outbound tcp --port-min 111 --port-max 2049 --remote 10.240.0.10 # VNI IP
-
创建使用 PVC 的部署。 只有在与您创建的规则匹配的工作程序节点上部署的 pod 才能够安装或使用 PVC。 部署在其他节点上的 pod 处于容器
creating
状态。
限制文件共享对单个专区中工作程序节点上的 Pod 的访问权
-
确保您已 完成先决条件。
-
将以下规则添加到先前创建的定制安全组。
ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.240.0.0/24 # zone subnet cidr range
-
在
kube-clusterID
安全组中添加以下规则。 指定虚拟网络接口 (VNI) 的 IP 地址。ibmcloud is sg-rulec kube-<cluster-ID> outbound tcp --port-min 111 --port-max 2049 --remote 10.240.0.10 # VNI IP
-
创建使用 PVC 的部署。 只有部署在先前规则中列出的区域中的 pod 才能安装 PVC。 部署在其他区域中的 pod 无法访问 PVC,并且处于容器
creating
状态。
限制文件共享对单个工作程序池中工作程序节点上的 pod 的访问权
-
确保您已 完成先决条件。
-
为每个工作池子网范围创建入站规则。
ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.240.0.0/24 # zone 1 subnet cidr range ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.240.1.0/24 # zone 2 subnet cidr range
-
在
kube-clusterID
安全组中添加以下规则。 指定虚拟网络接口 (VNI) 的 IP 地址作为远程或源。ibmcloud is sg-rulec kube-<cluster-ID> outbound tcp --port-min 111 --port-max 2049 --remote 10.240.0.10 # VNI IP
-
部署使用先前创建的 PVC 的应用程序。 只有先前规则中指示的工作程序池上的 pod 才能安装 PVC。 或者,如果在 daemonset 中部署应用程序,那么 pod 将仅在为其创建安全组规则的工作程序节点上成功部署。 不在指定工作程序池中的工作程序池上的 pod 因
MountVolume.SetUp failed for volume "pvc-184b8c92-33ea-4874-b2ac-17665e53c060" : rpc error: code = DeadlineExceeded desc = context deadline exceeded
错误而失败。
限制对多个工作程序池中工作程序节点上的 pod 的文件共享访问权
-
确保您已 完成先决条件。
-
在自定义安全组中添加以下规则。 指定工作程序池和子网 CIDR 范围作为远程或源。
ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.240.1.0/24 # worker pool 1, zone 1 subnet CIDR range ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.240.1.0/24 # worker pool 1, zone 2 subnet CIDR range ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.241.0.0/24 # worker pool 2, zone 1 subnet CIDR range ibmcloud is sg-rulec CUSTOM-SG inbound tcp --port-min 111 --port-max 2049 --remote 10.241.1.0/24 # worker pool 2, zone 2subnet CIDR range
-
在
kube-<clusterID>
安全组中添加以下规则。 指定虚拟网络接口 (VNI) 的 IP 地址作为远程或源。ibmcloud is sg-rulec kube-<clusterID> outbound tcp --port-min 111 --port-max 2049 --remote 10.240.1.7 # VNI-IP
-
创建使用 PVC 的部署。 只有部署在规则中指示的区域中的 pod 才能安装 PVC。 部署在受限工作程序节点上的 pod 将卡在容器
creating
状态。