1.8.2.4. 使用自动导入 secret 导入集群


要使用自动导入 secret,您必须创建一个 secret,其中包含集群的 kubeconfig 文件或 kube API 服务器和集群的令牌对。

  1. 检索您要导入的集群的 kubeconfig 文件或 kube API 服务器和令牌。请参阅 Kubernetes 集群的文档,了解在哪里可以找到您的 kubeconfig 文件或 kube API 服务器和令牌。
  2. 在 ${CLUSTER_NAME} 命名空间中创建 auto-import-secret.yaml 文件。

    1. 创建名为 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
      Copy to Clipboard Toggle word wrap
    2. 使用以下命令应用 ${CLUSTER_NAME} 命名空间中的 YAML 文件:

      oc apply -f auto-import-secret.yaml
      Copy to Clipboard Toggle word wrap

      注意: 默认情况下,导入过程完成后会使用自动导入 secret 一次并删除。如果要保留自动导入 secret,请将 managedcluster-import-controller.open-cluster-management.io/keeping-auto-import-secret 添加到 secret。您可以运行以下命令来添加它:

  3. 验证您的导入集群的 JOINEDAVAILABLE 状态。在 hub 集群中运行以下命令:

    oc get managedcluster ${CLUSTER_NAME}
    Copy to Clipboard Toggle word wrap
  4. 在受管集群中运行以下命令来登录到受管集群:

    oc login
    Copy to Clipboard Toggle word wrap
  5. 运行以下命令,以验证您要导入的集群中的 pod 状态:

    oc get pod -n open-cluster-management-agent
    Copy to Clipboard Toggle word wrap

继续 导入 klusterlet

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat