VPC: 为 IBM Cloud Object Storage 设置授权 IP 地址
虚拟私有云
您可以授权 VPC Cloud Service 端点源 IP 地址来访问 IBM Cloud Object Storage 存储区。 设置授权 IP 地址时,只能从这些 IP 地址 (例如,在应用程序 pod 中) 访问存储区数据。
- 最低必需许可权
- Red Hat OpenShift on IBM Cloud 服务的 管理者 服务访问角色。
- IBM Cloud Object Storage 服务的 写程序 服务访问角色。
-
遵循指示信息以安装
ibmc
Helm 插件。 确保安装ibm-object-storage-plugin
并将bucketAccessPolicy
选项设置为true
。 -
为 IBM Cloud Object Storage 实例创建一个
Manager
HMAC 服务凭证和一个Writer
HMAC 服务凭证。 -
将
apikey
从 IBM Cloud Object Storage 管理器凭证编码为 base64。echo -n "<cos_manager_apikey>" | base64
-
将
access-key
和secret-key
从 IBM Cloud Object Storage 写程序凭证编码为 base64。echo -n "<cos_writer_access-key>" | base64 echo -n "<cos_writer_secret-key>" | base64
-
使用您编码的值创建私钥配置文件。 对于
access-key
和secret-key
,从您创建的 Writer HMAC 凭证输入 base64 编码access-key
和secret-key
。 对于res-conf-apikey
,输入来自 Manager HMAC 凭证的 base64 编码apikey
。apiVersion: v1 kind: Secret metadata: name: <secret_name> type: ibm/ibmc-s3fs data: access-key: # Enter your base64 encoded COS Writer access-key secret-key: # Enter your base64 encoded COS Writer secret-key res-conf-apikey: # Enter your base64 encoded COS Manager api-key
-
在集群中创建私钥。
oc create -f secret.yaml
-
确认已创建私钥。
oc get secrets
-
创建使用您创建的私钥的 PVC。 设置
ibm.io/auto-create-bucket: "true"
和ibm.io/auto_cache: "true"
注释以自动创建用于高速缓存数据的存储区。kind: PersistentVolumeClaim apiVersion: v1 metadata: name: <pvc_name> annotations: ibm.io/auto-create-bucket: "true" ibm.io/auto-delete-bucket: "false" ibm.io/auto_cache: "true" ibm.io/bucket: "<bucket_name>" ibm.io/secret-name: "<secret_name>" ibm.io/secret-namespace: "<secret-namespace>" # By default, the COS plug-in searches for your secret in the same namespace where you create the PVC. If you created your secret in a namespace other than the namespace where you want to create your PVC, enter the namespace where you created your secret. spec: accessModes: - ReadWriteMany resources: requests: storage: 8Gi storageClassName: ibmc-s3fs-standard-regional volumeMode: Filesystem
-
获取 VPC 的云服务端点源 IP 地址的列表。
-
获取 VPC 的列表。
ibmcloud is vpcs
-
获取 VPC 的详细信息,并记录 Cloud Service 端点源 IP 地址。
ibmcloud is vpc <vpc_ID>
示例输出
... Cloud Service Endpoint source IP addresses: Zone Address us-south-1 10.249.XXX.XX us-south-2 10.249.XXX.XX us-south-3 10.249.XXX.XX
-
-
验证 VPC 的 Cloud Service 端点源 IP 地址是否已在 IBM Cloud Object Storage 存储区中获得授权。
-
从 IBM Cloud Object Storage 资源列表 中,选择 IBM Cloud Object Storage 实例,然后选择在 PVC 中指定的存储区。
-
选择 访问策略 > 授权 IP,并验证是否显示了 VPC 的 Cloud Service 端点源 IP 地址。
无法从控制台读取或写入存储区。 只能从集群上的应用程序 pod 中访问存储区。
-
在群集中创建应用程序。
oc create -f app.yaml
- 验证应用程序 pod 是否为
Running
。
oc get pods | grep <app_name>
-
验证卷是否已安装,以及您是否可以读写 COS 存储区。
-
登录应用程序 pod。
oc exec -it <pod_name> bash
-
验证是否从应用程序 pod 安装了 COS 存储区,以及您是否可以读写 COS 存储区。 运行磁盘可用
df
命令以查看系统中的可用磁盘。 COS 存储区显示您在 PVC 中指定的s3fs
文件系统类型和安装路径。df
在此示例中,COS 存储区安装在
/cos-vpc
上。Filesystem 1K-blocks Used Available Use% Mounted on overlay 102048096 9071556 87786140 10% / tmpfs 65536 0 65536 0% /dev tmpfs 7565792 0 7565792 0% /sys/fs/cgroup shm 65536 0 65536 0% /dev/shm /dev/vda2 102048096 9071556 87786140 10% /etc/hosts s3fs 274877906944 0 274877906944 0% /cos-vpc tmpfs 7565792 44 7565748 1% /run/secrets/kubernetes.io/serviceaccount tmpfs 7565792 0 7565792 0% /proc/acpi tmpfs 7565792 0 7565792 0% /proc/scsi tmpfs 7565792 0 7565792 0% /sys/firmware
-
将目录切换到安装 COS 存储区的目录。 在此示例中,存储区安装在
/cos-vpc
上。cd cos-vpc
-
将
test.txt
文件写入 COS 存储区和列表文件,以验证是否已写入该文件。touch test.txt && ls
-
除去文件并从应用程序 pod 注销。
rm test.txt && exit