7.2 KiB
| title | keywords | description | titleLink | weight |
|---|---|---|---|---|
| 导入 AWS EKS 集群 | Kubernetes, KubeSphere, 多集群, Amazon EKS | 了解如何导入 Amazon Elastic Kubernetes 服务集群。 | 导入 AWS EKS 集群 | 5320 |
本教程演示如何使用直接连接方法将 AWS EKS 集群导入 KubeSphere。如果您想使用代理连接方法,请参考代理连接。
准备工作
- 您需要准备一个已安装 KubeSphere 的 Kubernetes 集群,并将其设置为 Host 集群。有关如何准备 Host 集群的更多信息,请参考准备 Host 集群。
- 您需要准备一个 EKS 集群,用作 Member 集群。
导入 EKS 集群
步骤 1:在 EKS 集群上部署 KubeSphere
您需要首先在 EKS 集群上部署 KubeSphere。有关如何在 EKS 上部署 KubeSphere 的更多信息,请参考在 AWS EKS 上部署 KubeSphere。
步骤 2:准备 EKS Member 集群
-
为了通过 Host 集群管理 Member 集群,您需要使它们之间的
jwtSecret相同。首先,需要在 Host 集群上执行以下命令获取jwtSecret。kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret输出类似如下:
jwtSecret: "QVguGh7qnURywHn2od9IiOX6X8f8wK8g" -
以
admin身份登录 EKS 集群的 KubeSphere Web 控制台。点击左上角的平台管理,选择集群管理。 -
访问 CRD,在搜索栏输入
ClusterConfiguration,然后按下键盘上的回车键。点击 ClusterConfiguration 访问其详情页。 -
点击右侧的
,选择编辑配置文件来编辑 ks-installer。 -
在
ks-installer的 YAML 文件中,将jwtSecret的值改为如上所示的相应值,将clusterRole的值改为member。点击更新保存更改。authentication: jwtSecret: QVguGh7qnURywHn2od9IiOX6X8f8wK8gmulticluster: clusterRole: member{{< notice note >}}
请确保使用您自己的
jwtSecret。您需要等待一段时间使更改生效。{{</ notice >}}
步骤 3:创建新的 KubeConfig 文件
-
Amazon EKS 不像标准的 kubeadm 集群那样提供内置的 KubeConfig 文件。但您可以参考此文档创建 KubeConfig 文件。生成的 KubeConfig 文件类似如下:
apiVersion: v1 clusters: - cluster: server: <endpoint-url> certificate-authority-data: <base64-encoded-ca-cert> name: kubernetes contexts: - context: cluster: kubernetes user: aws name: aws current-context: aws kind: Config preferences: {} users: - name: aws user: exec: apiVersion: client.authentication.k8s.io/v1alpha1 command: aws args: - "eks" - "get-token" - "--cluster-name" - "<cluster-name>" # - "--role" # - "<role-arn>" # env: # - name: AWS_PROFILE # value: "<aws-profile>"但是,自动生成的 KubeConfig 文件要求使用此 KubeConfig 的每台计算机均安装有
aws命令(aws CLI 工具)。 -
在本地计算机上运行以下命令,获得由 KubeSphere 创建的 ServiceAccount
kubesphere的令牌,该令牌对集群具有集群管理员访问权限,并将用作新的 KubeConfig 令牌。TOKEN=$(kubectl -n kubesphere-system get secret $(kubectl -n kubesphere-system get sa kubesphere -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 -d) kubectl config set-credentials kubesphere --token=${TOKEN} kubectl config set-context --current --user=kubesphere -
运行以下命令获取新的 KubeConfig 文件:
cat ~/.kube/config输出类似如下,可以看到已插入新用户
kubesphere并已将其设置为当前集群环境上下文 (current-context) 用户:apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZ...S0tLQo= server: https://*.sk1.cn-north-1.eks.amazonaws.com.cn name: arn:aws-cn:eks:cn-north-1:660450875567:cluster/EKS-LUSLVMT6 contexts: - context: cluster: arn:aws-cn:eks:cn-north-1:660450875567:cluster/EKS-LUSLVMT6 user: kubesphere name: arn:aws-cn:eks:cn-north-1:660450875567:cluster/EKS-LUSLVMT6 current-context: arn:aws-cn:eks:cn-north-1:660450875567:cluster/EKS-LUSLVMT6 kind: Config preferences: {} users: - name: arn:aws-cn:eks:cn-north-1:660450875567:cluster/EKS-LUSLVMT6 user: exec: apiVersion: client.authentication.k8s.io/v1alpha1 args: - --region - cn-north-1 - eks - get-token - --cluster-name - EKS-LUSLVMT6 command: aws env: null - name: kubesphere user: token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImlCRHF4SlE5a0JFNDlSM2xKWnY1Vkt5NTJrcDNqRS1Ta25IYkg1akhNRmsifQ.eyJpc3M................9KQtFULW544G-FBwURd6ArjgQ3Ay6NHYWZe3gWCHLmag9gF-hnzxequ7oN0LiJrA-al1qGeQv-8eiOFqX3RPCQgbybmix8qw5U6f-Rwvb47-xA您可以运行以下命令检查新的 KubeConfig 是否有权限访问 EKS 集群。
kubectl get nodes输出类似如下:
NAME STATUS ROLES AGE VERSION ip-10-0-47-38.cn-north-1.compute.internal Ready <none> 11h v1.18.8-eks-7c9bda ip-10-0-8-148.cn-north-1.compute.internal Ready <none> 78m v1.18.8-eks-7c9bda





