設定 Kubernetes 角色型存取控制 - Amazon SageMaker

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

設定 Kubernetes 角色型存取控制

叢集管理員使用者也需要設定 Kubernetes 角色型存取控制 (RBAC),讓資料科學家使用者使用 SageMaker HyperPod CLI,在與 Amazon 協調的 HyperPod 叢集上執行工作負載EKS。

選項 1:RBAC使用 Helm Chart 設定

SageMaker HyperPod 服務團隊提供 Helm 子圖表,用於設定 RBAC。如需進一步了解,請參閱 使用 Helm 在 Amazon EKS叢集上安裝套件

選項 2:RBAC手動設定

ClusterRoleBinding 建立具有最低權限的 ClusterRole 和 ,以及建立RoleBinding具有突變許可的 Role和 。

ClusterRoleBinding為資料科學家IAM角色建立 ClusterRole

建立叢集層級組態檔案cluster_level_config.yaml,如下所示。

kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: hyperpod-scientist-user-cluster-role rules: - apiGroups: [""] resources: ["pods"] verbs: ["list"] - apiGroups: [""] resources: ["nodes"] verbs: ["list"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: hyperpod-scientist-user-cluster-role-binding subjects: - kind: Group name: hyperpod-scientist-user-cluster-level apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: hyperpod-scientist-user-cluster-role # this must match the name of the Role or ClusterRole you wish to bind to apiGroup: rbac.authorization.k8s.io

將組態套用至EKS叢集。

kubectl apply -f cluster_level_config.yaml

建立角色和 RoleBinding 命名空間

這是執行訓練任務的命名空間訓練運算子,依預設,恢復能力會進行監控。任務自動恢復只能在kubeflow命名空間或命名空間字首 中支援aws-hyperpod

建立角色組態檔案namespace_level_role.yaml,如下所示。此範例會在kubeflow命名空間中建立角色

kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: kubeflow name: hyperpod-scientist-user-namespace-level-role ### # 1) add/list/describe/delete pods # 2) get/list/watch/create/patch/update/delete/describe kubeflow pytroch job # 3) get pod log ### rules: - apiGroups: [""] resources: ["pods"] verbs: ["create", "get"] - apiGroups: [""] resources: ["nodes"] verbs: ["get", "list"] - apiGroups: [""] resources: ["pods/log"] verbs: ["get", "list"] - apiGroups: [""] resources: ["pods/exec"] verbs: ["get", "create"] - apiGroups: ["kubeflow.org"] resources: ["pytorchjobs", "pytorchjobs/status"] verbs: ["get", "list", "create", "delete", "update", "describe"] - apiGroups: [""] resources: ["configmaps"] verbs: ["create", "update", "get", "list", "delete"] - apiGroups: [""] resources: ["secrets"] verbs: ["create", "get", "list", "delete"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: namespace: kubeflow name: hyperpod-scientist-user-namespace-level-role-binding subjects: - kind: Group name: hyperpod-scientist-user-namespace-level apiGroup: rbac.authorization.k8s.io roleRef: kind: Role name: hyperpod-scientist-user-namespace-level-role # this must match the name of the Role or ClusterRole you wish to bind to apiGroup: rbac.authorization.k8s.io

將組態套用至EKS叢集。

kubectl apply -f namespace_level_role.yaml

建立 Kubernetes 群組的存取項目

RBAC 使用上述兩個選項之一進行設定後,請使用下列範例命令取代必要資訊。

aws eks create-access-entry \ --cluster-name <eks-cluster-name> \ --principal-arn arn:aws:iam::<AWS_ACCOUNT_ID_SCIENTIST_USER>:role/ScientistUserRole \ --kubernetes-groups '["hyperpod-scientist-user-namespace-level","hyperpod-scientist-user-cluster-level"]'

對於 principal-arn 參數,您需要使用 IAM科學家的用戶