

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Studio 中設定 Amazon EKS 叢集
<a name="sagemaker-hyperpod-studio-setup-eks"></a>

下列指示描述如何在 Studio 中設定 Amazon EKS 叢集。

1. 建立網域或備妥網域。如需建立網域的詳細資訊，請參閱[使用 Amazon SageMaker AI 進行設定的指南](gs.md)。

1. 將以下許可新增到您的執行角色。

   如需 SageMaker AI 執行角色以及如何編輯這些角色的相關資訊，請參閱 [了解網域空間許可和執行角色](execution-roles-and-spaces.md)。

   若要了解如何將政策附加至 IAM 使用者或群組，請參閱[新增和移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "DescribeHyerpodClusterPermissions",
               "Effect": "Allow",
               "Action": [
                   "sagemaker:DescribeCluster"
               ],
               "Resource": "arn:aws:sagemaker:{{us-east-1}}:{{111122223333}}:cluster/{{cluster-name}}"
           },
           {
               "Effect": "Allow",
               "Action": "ec2:Describe*",
               "Resource": "*"
           },
           {
               "Effect": "Allow",
               "Action": [
                   "ecr:CompleteLayerUpload",
                   "ecr:GetAuthorizationToken",
                   "ecr:UploadLayerPart",
                   "ecr:InitiateLayerUpload",
                   "ecr:BatchCheckLayerAvailability",
                   "ecr:PutImage"
               ],
               "Resource": "*"
           },
           {
               "Effect": "Allow",
                   "Action": [
                       "cloudwatch:PutMetricData",
                       "cloudwatch:GetMetricData"
                       ],
               "Resource": "*"
           },
           {
               "Sid": "UseEksClusterPermissions",
               "Effect": "Allow",
               "Action": [
                   "eks:DescribeCluster",
                   "eks:AccessKubernetesApi",
                   "eks:DescribeAddon"
               ],
               "Resource": "arn:aws:eks:{{us-east-1}}:{{111122223333}}:cluster/{{cluster-name}}"
           },
           {
               "Sid": "ListClustersPermission",
               "Effect": "Allow",
               "Action": [
                   "sagemaker:ListClusters"
               ],
               "Resource": "*"
           },
           {
               "Effect": "Allow",
               "Action": [
                   "ssm:StartSession",
                   "ssm:TerminateSession"
               ],
               "Resource": "*"
           }
       ]
   }
   ```

------

1. [使用 EKS 存取項目授予 IAM 使用者 Kubernetes 的存取權](https://docs.aws.amazon.com/eks/latest/userguide/access-entries.html)。

   1. 導覽至與 HyperPod 叢集相關聯的 Amazon EKS 叢集。

   1. 選擇**存取**索引標籤，並為您建立的執行角色[建立存取項目](https://docs.aws.amazon.com/eks/latest/userguide/creating-access-entries.html)。

      1. 在步驟 1 中，於 **IAM** 主體下拉式清單中選取您在上方建立的執行角色。

      1. 在步驟 2 中，選取一個政策名稱，然後選取您想要使用者能夠存取的存取範圍。

1. (選用) 為了確保更順暢的體驗，建議您將標籤新增至叢集。如需如何新增標籤的相關資訊，請參閱 [編輯 SageMaker HyperPod 叢集](sagemaker-hyperpod-operate-slurm-console-ui.md#sagemaker-hyperpod-operate-slurm-console-ui-edit-clusters) 以使用 SageMaker AI 主控台更新叢集。

   1. 將 [Amazon Managed Grafana](https://docs.aws.amazon.com/grafana/latest/userguide/what-is-Amazon-Managed-Service-Grafana.html) 工作區標記到您的 Studio 網域。這將用來直接從 Studio 中的叢集快速連結至 Grafana 工作區。若要這樣做，請將下列標籤新增至您的叢集，以使用 Grafana 工作區 ID `ws-id` 來識別它。

     標籤金鑰 = “`grafana-workspace`”、標籤值 = “`ws-id`”。

1. (選用) [限制 Studio for EKS 叢集中的任務檢視](#sagemaker-hyperpod-studio-setup-eks-restrict-tasks-view)。如需 Studio 中可檢視任務的相關資訊，請參閱 [任務​](sagemaker-hyperpod-studio-tabs.md#sagemaker-hyperpod-studio-tabs-tasks)。

## 限制 Studio for EKS 叢集中的任務檢視
<a name="sagemaker-hyperpod-studio-setup-eks-restrict-tasks-view"></a>

您可以限制使用者的 Kubernetes 命名空間許可，以便他們只能檢視屬於指定命名空間的任務。以下提供如何在 Studio for EKS 叢集中限制任務檢視的相關資訊。如需 Studio 中可檢視任務的相關資訊，請參閱 [任務​](sagemaker-hyperpod-studio-tabs.md#sagemaker-hyperpod-studio-tabs-tasks)。

使用者預設會看到所有 EKS 叢集任務。您可以將使用者對 EKS 叢集任務的可見性限制在指定的命名空間，確保使用者可以存取所需的資源，同時保持嚴格的存取控制。一旦設定了以下內容，您就需要提供命名空間，讓使用者顯示該命名空間的任務。

一旦套用了限制，您就需要將命名空間提供給擔任該角色的使用者。一旦使用者提供其可在**命名空間**索引標籤中檢視的輸入命名空間，Studio 只會顯示命名空間的任務。

下列組態可讓管理員授予資料科學家特定、有限的存取權，以檢視叢集內的任務。此組態授予下列許可：
+ 列出並取得 Pod
+ 列出並取得事件
+ 取得自訂資源定義 (CRD)

YAML 組態

```
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pods-events-crd-cluster-role
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list"]
- apiGroups: [""]
  resources: ["events"]
  verbs: ["get", "list"]
- apiGroups: ["apiextensions.k8s.io"]
  resources: ["customresourcedefinitions"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: pods-events-crd-cluster-role-binding
subjects:
- kind: Group
  name: pods-events-crd-cluster-level
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: pods-events-crd-cluster-role
  apiGroup: rbac.authorization.k8s.io
```

1. 將 YAML 組態儲存到名為 `cluster-role.yaml` 的檔案。

1. 使用 [https://kubernetes.io/docs/reference/kubectl/](https://kubernetes.io/docs/reference/kubectl/) 套用組態：

   ```
   kubectl apply -f cluster-role.yaml
   ```

1. 驗證組態：

   ```
   kubectl get clusterrole pods-events-crd-cluster-role
   kubectl get clusterrolebinding pods-events-crd-cluster-role-binding
   ```

1. 透過您的身分提供者或 IAM 將使用者指派給 `pods-events-crd-cluster-level` 群組。