安装IBM Cloud Object Storage集群附加组件
IBM Cloud Object Storage集群插件的测试版仅适用于允许列表账户。 要添加到允许列表,请联系支持部门。 有关更多信息,请参阅 请求访问允许列表功能。
先决条件
- IBM Cloud Object Storage 插件至少需要 0.2、vCPU 和128 MB内存。
- 建立 IBM Cloud Object Storage 实例。
了解水桶的创建和移除
- 您可以通过在 PVC 中指定水桶名称来使用现有的水桶。
- 如果您提供了一个水桶名称,而该水桶并不存在,那么就会创建一个具有该名称的水桶。
- 如果不提供存储桶名称,则会创建一个命名为
temp-xxx
的存储桶。 - 根据存储类中定义的回收策略删除存储桶。
- 如果设置了
reclaimPolicy: Delete
,则在删除 PVC 时删除水桶。 - 如果设置了
reclaimPolicy: Retain
,则即使删除了 PVC,也会保留水桶。
- 如果设置了
启用IBM Cloud Object Storage附加组件
开始之前 访问你的Red Hat OpenShift集群。
- 列出附加组件并找到要安装的版本。
示例输出ibmcloud oc cluster addon versions
OK Name Version Supported Kubernetes Range Supported OpenShift Range Kubernetes Default OpenShift Default ibm-object-csi-driver 0.1 (default) >=1.30.0 >=4.15.0 - -
- 安装插件。
ibmcloud oc cluster addon enable ibm-object-csi-driver --cluster CLUSTER [--version VERSION]
- 验证安装。
ibmcloud oc cluster addon ls --cluster CLUSTER
OK Name Version Health State Health Status ibm-object-csi-driver 0.1 normal Addon Ready. For more info: http://ibm.biz/addon-state (H1500)
- 列出可用的存储类别。
oc get sc | grep object
ibm-object-storage-smart-rclone cos.s3.csi.ibm.io Delete Immediate false 17h ibm-object-storage-smart-rclone-retain cos.s3.csi.ibm.io Retain Immediate false 17h ibm-object-storage-smart-s3fs cos.s3.csi.ibm.io Delete Immediate false 17h ibm-object-storage-smart-s3fs-retain cos.s3.csi.ibm.io Retain Immediate false 17h ibm-object-storage-standard-rclone cos.s3.csi.ibm.io Delete Immediate false 17h ibm-object-storage-standard-rclone-retain cos.s3.csi.ibm.io Retain Immediate false 17h ibm-object-storage-standard-s3fs cos.s3.csi.ibm.io Delete Immediate false 17h ibm-object-storage-standard-s3fs-retain cos.s3.csi.ibm.io Retain Immediate false 17h
部署使用IBM Cloud Object Storage的应用程序
创建一个包含 COS 凭据的Kubernetes秘密。
-
将以下配置保存为名为
secret.yaml
.- 对于 IAM 凭据,请使用
apiKey
和serviceId
的组合,来自 Object Storage。 - 对于 HMAC 凭据,请使用
accessKey
和secretKey
,来自 Object Storage。
apiVersion: v1 kind: Secret type: cos-s3-csi-driver metadata: name: cos-secret-1 # Name your secret. This same name is used for the PVC in the following steps. namespace: <namespace> # Specify the namespace where you want to create the secret. data: bucketName: <base64-encoded-bucket-name> apiKey: <base64-encoded-COS-Service-Instance-API-key> serviceID: <base64-encoded-COS-service-ID> accessKey: <base64-encoded-HMAC-access-key> secretKey: <base64-encoded-HMAC-secret-key> stringData: # uid: "3000" # Optional: Provide a uid to run as non root user. This must match runAsUser in SecurityContext of pod spec. mountOptions: | # Review or update the following default s3fs mount options #max_stat_cache_size=100000 #mp_umask=002 #parallel_count=8 # value depends on the storage class used #sigv2 #use_path_request_style #default_acl=private #kernel_cache #multipart_size=62 #retries=5 #allow_other #max_dirty_data=51200 # Review or update the following default rclone mount options #--allow-other=true #--daemon=true #acl=private #upload_cutoff=256Mi #chunk_size=64Mi #upload_concurrency=20 #copy_cutoff=1Gi #memory_pool_flush_time=30s #disable_checksum=true #bucket_acl=private #max_upload_parts=64
- mountOptions
- 您可以通过编辑密文中的
mountOptions
来自定义s3fs
或rclone
的挂载选项。 更多信息,请参阅 s3fs 挂载选项和 rclone 挂载选项。
目前,该附加组件已启用,以支持固定的挂载选项集,并对每个挂载选项进行适当的验证。 如果要使用验证列表中没有的其他安装选项,请联系支持部门启用这些选项。
- 对于 IAM 凭据,请使用
-
将上一节中获取的凭据编码为base64。 对每个参数重复此命令。
echo -n "<value>" | base64
-
用base64编码值更新配置文件。
-
创建私钥。
oc apply -f secret.yaml
创建 PVC
您可以在多个 PVC 中使用一个密文,也可以在每个 PVC 中使用一个密文。
您可以在 PVC yaml 中使用以下注解来管理这种行为。 这些注释有助于驱动程序将 PVC 映射到正确的密文中。
cos.csi.driver/secret: "<custom-secret>"
cos.csi.driver/secret-namespace: "<namespace>"
确保您的秘密、PVC 和 pod 都在同一个命名空间中
1-to-1 保密信息到 PVC 映射的 PVC 示例,为您的 PVC 赋予与您之前创建的保密信息相同的名称。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cos-secret-1 # Give your PVC the same name as the secret you created in the previous step.
namespace: <namespace> # The namespace where you want to create the PVC.
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: <storage_class_name> # The storage class you want to use.
通过使用注释指定密文,将 1 个密文用于多个 PVC 的 PVC 示例。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cos-csi-pvc1
namespace: <namespace> # The namespace where you want to create the PVC.
annotations:
cos.csi.driver/secret: "<custom-secret>"
cos.csi.driver/secret-namespace: "<namespace>"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 256Mi
storageClassName: <storage_class_name> # The storage class you want to use.
-
从前面的示例中选择一个,并根据自己的使用情况进行定制。 有关存储类的列表,请参阅 存储类参考。
-
创建 PVC。
oc apply -f pvc.yaml
创建部署
-
将以下配置保存到名为
dep.yaml
.apiVersion: apps/v1 kind: Deployment metadata: name: <name> labels: app: <name> spec: replicas: 1 selector: matchLabels: app: <name> template: metadata: labels: app: <name> spec: containers: - name: app-frontend image: <image> # Enter your app image. imagePullPolicy: IfNotPresent volumeMounts: - mountPath: <path_you_want_to_mount_the_volume_on> # For example `/dev` name: cos-csi-volume volumes: - name: cos-csi-volume persistentVolumeClaim: claimName: <pvc_name> # Enter the name of the PVC you created earlier.
-
创建部署。
oc apply -f dep.yaml
禁用IBM Cloud Object Storage附加组件
- 运行以下命令禁用该插件。
示例输出ibmcloud oc cluster addon disable ibm-object-csi-driver --cluster CLUSTER
Data and resources that you created for the add-on might be deleted when the add-on is disabled. Continue? [y/N]> y Disabling add-on ibm-object-csi-driver for cluster XXX... OK
- 验证是否已删除附加组件。
ibmcloud oc cluster addon ls --cluster CLUSTER
从Helm插件迁移到群集插件
-
获取 PVC 的详细信息并选择一个进行迁移。
oc get pvc --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' | tail -n +2 | while read namespace pvc; do kubectl describe pvc "$pvc" -n "$namespace" | grep 'volume.kubernetes.io/storage-provisioner: ibm.io/ibmc-s3fs' > /dev/null ; if [ $? -eq 0 ]; then echo "PVC: $pvc in Namespace: $namespace uses ibm.io/ibmc-s3fs storage provisioner"; fi; done
示例输出
PVC: pvc-test in Namespace: default uses ibm.io/ibmc-s3fs storage provisioner
-
描述 PVC 并获取水桶名称。
oc describe pvc <pvc_name> | grep ibm.io/bucket:
示例输出
ibm.io/bucket: test-s3
-
重现您的秘密,并附上水桶名称。
apiVersion: v1 kind: Secret type: cos-s3-csi-driver metadata: name: cos-secret-1 # Name your secret. namespace: <namespace> # Specify the namespace where you want to create the secret. data: bucketName: <base64-encoded-bucket-name> accessKey: <base64-encoded-HMAC-access-key> secretKey: <base64-encoded-HMAC-secret-key> stringData: # uid: "3000" # Optional: Provide a uid to run as non root user. This must match runAsUser in SecurityContext of pod spec. mountOptions: | key1=value1 key2=value2
-
查找 PVC 中使用的存储类。
oc describe pvc <pvc_name> | grep StorageClass:
名为
test-s3
的 PVC 的命令示例。oc describe pvc test-s3 | grep StorageClass:
示例输出
StorageClass: ibmc-s3fs-smart-perf-regional
-
查看新的存储类别 that are available with the add-on and select a replacement class.
- 如果您使用的是
flex
类,请选择一个新的smart
类。 - 如果您使用的是
standard
类,请选择一个新的standard
类。 - 附加组件不再提供
cold
和vault
类,请选择smart
或standard
类。
- 如果您使用的是
-
查看 PVC 的详细信息。
oc describe pvc test-s3
示例输出
Name: pvc-test Namespace: default StorageClass: ibmc-s3fs-smart-perf-regional Status: Bound Volume: pvc-c625474d-31f0-4929-bc3e-feace1fb42fb Labels: <none> Annotations: ibm.io/auto-create-bucket: true ibm.io/auto-delete-bucket: true ibm.io/bucket: bha-test-s23 ibm.io/secret-name: satstoragesecret pv.kubernetes.io/bind-completed: yes pv.kubernetes.io/bound-by-controller: yes volume.beta.kubernetes.io/storage-provisioner: ibm.io/ibmc-s3fs volume.kubernetes.io/storage-provisioner: ibm.io/ibmc-s3fs Finalizers: [kubernetes.io/pvc-protection] Capacity: 3Gi Access Modes: RWO VolumeMode: Filesystem Used By: test-pod Events: <none>
-
创建一个替代 PVC,使用新的存储类并引用你之前创建的秘密。
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: cos-csi-pvc1 namespace: <namespace> # The namespace where you want to create the PVC. annotations: cos.csi.driver/secret: "cos-secret-1" # Secret created in step 4 cos.csi.driver/secret-namespace: "<secret_namespace>" spec: accessModes: - ReadWriteOnce resources: requests: storage: 256Mi storageClassName: <storage_class_name> # The storage class you picked based on old storage class mapping.
-
确认 PVC 为
Bound
。oc get pvc
-
获取应用程序的详细信息。
oc get pods
-
将应用程序的规模缩小到零。
kubectl scale deployment --replicas=0 my-app
-
创建一个替换部署,引用上一步中创建的 PVC。
-
新部署运行后,可以删除旧部署。
-
对要迁移的每个 PVC 重复上述步骤。
IBM Cloud Object Storage集群附加存储类
名称 | 回收策略 | 绑定方式 |
---|---|---|
ibm-object-storage-smart-rclone | 删除(T) | 立即 |
ibm-object-storage-smart-rclone-retain | Retain | 立即 |
ibm-object-storage-smart-s3fs | 删除(T) | 立即 |
ibm-object-storage-smart-s3fs-retain | Retain | 立即 |
ibm-object-storage-standard-rclone | 删除(T) | 立即 |
ibm-object-storage-standard-rclone-retain | Retain | 立即 |
ibm-object-storage-standard-s3fs | 删除(T) | 立即 |
ibm-object-storage-standard-s3fs-retain | Retain | 立即 |