3.7. 使用 ccoctl 工具为 OpenShift Container Platform 组件创建凭证
您可以使用 OpenShift Container Platform Cloud Credential Operator(CCO)实用程序自动为每个集群组件创建 Alibaba Cloud RAM 用户和策略。
默认情况下,ccoctl 在运行命令的目录中创建对象。要在其他目录中创建对象,请使用 --output-dir 标志。此流程使用 <path_to_ccoctl_output_dir> 来引用这个目录。
先决条件
您必须:
-
提取并准备好
ccoctl二进制文件。 - 创建具有足够权限来创建 OpenShift Container Platform 集群的 RAM 用户。
-
将 RAM 用户的 AccessKeyID(
access_key_id)和 AccessKeySecret(access_key_secret)添加到本地计算机上的~/.alibabacloud/credentials文件中。
流程
运行以下命令设置
$RELEASE_IMAGE变量:RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')$ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令,从 OpenShift Container Platform 发行镜像中提取
CredentialsRequest对象列表:oc adm release extract \ --from=$RELEASE_IMAGE \ --credentials-requests \ --cloud=alibabacloud \ --to=<path_to_directory_with_list_of_credentials_requests>/credrequests
$ oc adm release extract \ --from=$RELEASE_IMAGE \ --credentials-requests \ --cloud=alibabacloud \ --to=<path_to_directory_with_list_of_credentials_requests>/credrequests1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
credrequests是存储CredentialsRequest对象列表的目录。如果该目录不存在,此命令就会创建该目录。
注意运行此命令可能需要一些时间。
如果您的集群使用集群功能禁用一个或多个可选组件,请删除任何禁用组件的
CredentialsRequest自定义资源。Alibaba Cloud 上 OpenShift Container Platform 4.13 的
credrequests目录的内容示例0000_30_machine-api-operator_00_credentials-request.yaml 0000_50_cluster-image-registry-operator_01-registry-credentials-request-alibaba.yaml 0000_50_cluster-ingress-operator_00-ingress-credentials-request.yaml 0000_50_cluster-storage-operator_03_credentials_request_alibaba.yaml
0000_30_machine-api-operator_00_credentials-request.yaml1 0000_50_cluster-image-registry-operator_01-registry-credentials-request-alibaba.yaml2 0000_50_cluster-ingress-operator_00-ingress-credentials-request.yaml3 0000_50_cluster-storage-operator_03_credentials_request_alibaba.yaml4 Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用
ccoctl工具处理credrequests目录中的所有CredentialsRequest对象:运行以下命令使用该工具:
ccoctl alibabacloud create-ram-users \ --name <name> \ --region=<alibaba_region> \ --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests \ --output-dir=<path_to_ccoctl_output_dir>
$ ccoctl alibabacloud create-ram-users \ --name <name> \ --region=<alibaba_region> \ --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests \ --output-dir=<path_to_ccoctl_output_dir>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 其中:
-
<name>是用于标记为跟踪而创建的云资源的名称。 -
<alibaba_region>是创建云资源的 Alibaba Cloud 区域。 -
<path_to_directory_with_list_of_requests>/credrequests是含有组件CredentialsRequest对象的文件的目录。 -
<path_to_ccoctl_output_dir>是放置所生成的组件凭证 secret 的目录。
注意如果您的集群使用
TechPreviewNoUpgrade功能集启用的技术预览功能,则必须包含--enable-tech-preview参数。输出示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意RAM 用户可以同时具有两个 accessKeys。如果您运行
ccoctl alibabacloud create-ram-users两次,则之前生成的 manifests secret 将变为过时,您必须重新应用新生成的 secret。-
验证 OpenShift Container Platform secret 是否已创建:
ls <path_to_ccoctl_output_dir>/manifests
$ ls <path_to_ccoctl_output_dir>/manifestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例:
openshift-cluster-csi-drivers-alibaba-disk-credentials-credentials.yaml openshift-image-registry-installer-cloud-credentials-credentials.yaml openshift-ingress-operator-cloud-credentials-credentials.yaml openshift-machine-api-alibabacloud-credentials-credentials.yaml
openshift-cluster-csi-drivers-alibaba-disk-credentials-credentials.yaml openshift-image-registry-installer-cloud-credentials-credentials.yaml openshift-ingress-operator-cloud-credentials-credentials.yaml openshift-machine-api-alibabacloud-credentials-credentials.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow 您可以通过查询 Alibaba Cloud 来验证是否创建了 RAM 用户和策略。如需更多信息,请参阅 Alibaba Cloud 文档中有关列出 RAM 用户和策略的内容。
将生成的凭证文件复制到目标清单目录中:
cp ./<path_to_ccoctl_output_dir>/manifests/*credentials.yaml ./<path_to_installation>dir>/manifests/
$ cp ./<path_to_ccoctl_output_dir>/manifests/*credentials.yaml ./<path_to_installation>dir>/manifests/Copy to Clipboard Copied! Toggle word wrap Toggle overflow 其中:
<path_to_ccoctl_output_dir>-
指定
ccoctl alibabacloud create-ram-users命令创建的目录。 <path_to_installation_dir>- 指定安装程序在其中创建文件的目录。