1.8.2.4. 使用自动导入 secret 导入集群
要使用自动导入 secret,您必须创建一个 secret,其中包含集群的 kubeconfig 文件或 kube API 服务器和集群的令牌对。
-
检索您要导入的集群的
kubeconfig文件或 kube API 服务器和令牌。请参阅 Kubernetes 集群的文档,了解在哪里可以找到您的kubeconfig文件或 kube API 服务器和令牌。 在 ${CLUSTER_NAME} 命名空间中创建
auto-import-secret.yaml文件。创建名为
auto-import-secret.yaml的 YAML 文件,其中包含类似以下模板的内容:apiVersion: v1 kind: Secret metadata: name: auto-import-secret namespace: <cluster_name> stringData: autoImportRetry: "5" # If you are using the kubeconfig file, add the following value for the kubeconfig file # that has the current context set to the cluster to import: kubeconfig: |- <kubeconfig_file> # If you are using the token/server pair, add the following two values instead of # the kubeconfig file: token: <Token to access the cluster> server: <cluster_api_url> type: Opaque使用以下命令应用 ${CLUSTER_NAME} 命名空间中的 YAML 文件:
oc apply -f auto-import-secret.yaml注意: 默认情况下,导入过程完成后会使用自动导入 secret 一次并删除。如果要保留自动导入 secret,请将
managedcluster-import-controller.open-cluster-management.io/keeping-auto-import-secret添加到 secret。您可以运行以下命令来添加它:
验证您的导入集群的
JOINED和AVAILABLE状态。在 hub 集群中运行以下命令:oc get managedcluster ${CLUSTER_NAME}在受管集群中运行以下命令来登录到受管集群:
oc login运行以下命令,以验证您要导入的集群中的 pod 状态:
oc get pod -n open-cluster-management-agent
继续 导入 klusterlet。