Helm Chart RBAC#

KubeRay 利用 Kubernetes 基于角色的访问控制 (RBAC) 资源来授予监控和管理资源的权限。本文档介绍了如何配置 KubeRay Helm chart 以创建 RBAC 资源用于 3 种不同的用例。

参数#

你可以通过修改 values.yaml 中的以下参数来配置 KubeRay Helm chart,以便为不同的用例创建 RBAC 资源。然后,你可以使用修改后的 values.yaml 安装 KubeRay Helm chart。

# Step 1: Clone the KubeRay repository
# Step 2: Modify the helm-chart/kuberay-operator/values.yaml
# Step 3: Install the KubeRay Helm chart (path: helm-chart/kuberay-operator)
helm install kuberay-operator .
  • rbacEnable

    • 如果为 true,Helm chart 会创建 RBAC 资源。如果为 false,则不会创建任何 RBAC 资源。默认值:true。

  • singleNamespaceInstall

    • 如果为 true,Helm chart 会创建命名空间范围的 RBAC 资源,即 Role 和 RoleBinding。如果为 false,则会创建集群范围的 RBAC 资源,即 ClusterRole 和 ClusterRoleBinding。默认值:false。

  • watchNamespace

    • 一个命名空间列表,KubeRay operator 的 informer 会监控这些命名空间中的自定义资源。

  • crNamespacedRbacEnable

    • 大多数情况下设为 true。在使用 GitOps 工具(如 ArgoCD)管理的 Kubernetes 集群的罕见情况下,设为 false。更多详情请参考 ray-project/kuberay#1162。默认值:true。

安装 KubeRay Helm chart 时,values.yaml 文件包含参数的详细描述。请参阅以下 pull requests 了解参数的更多背景信息

用例 1:监控 Kubernetes 集群中的所有命名空间#

Watch all namespaces in the Kubernetes cluster

默认情况下,KubeRay operator 的 informer 会监控 Kubernetes 集群中的所有命名空间。operator 拥有集群范围的权限来创建和管理资源,使用 ClusterRole 和 ClusterRoleBinding。

# Create a Kubernetes cluster using Kind.
kind create cluster --image=kindest/node:v1.26.0

# Create namespaces.
kubectl create ns n1
kubectl create ns n2

# Install a KubeRay operator. Use the default `values.yaml` file.
# (path: helm-chart/kuberay-operator)
helm install kuberay-operator .

# Check ClusterRole.
kubectl get clusterrole | grep kuberay
# kuberay-operator                  2023-10-15T04:54:28Z

# Check Role.
kubectl get role
#NAME                               CREATED AT
#kuberay-operator-leader-election   2023-10-15T04:54:28Z

# Install RayCluster in the `default`, `n1`, and `n2` namespaces.
helm install raycluster kuberay/ray-cluster --version 1.3.0
helm install raycluster kuberay/ray-cluster --version 1.3.0 -n n1
helm install raycluster kuberay/ray-cluster --version 1.3.0 -n n2

# You should create a RayCluster in these 3 namespaces.
kubectl get raycluster -A
# NAMESPACE   NAME                 DESIRED WORKERS   AVAILABLE WORKERS   STATUS   AGE
# default     raycluster-kuberay   1                 1                   ready    73s
# n1          raycluster-kuberay   1                 1                   ready    56s
# n2          raycluster-kuberay   1                 1                   ready    52s

用例 2:监控 Operator 部署所在的命名空间#

Watch the namespace where you deployed the operator

KubeRay operator 的 informer 会监控你部署 operator 所在的命名空间。operator 在同一命名空间中拥有 Role 和 RoleBinding。

  • values.yaml 文件中的 singleNamespaceInstall 参数修改为 true

    singleNamespaceInstall: true
    
# Create a Kubernetes cluster using Kind.
kind create cluster --image=kindest/node:v1.26.0

# Create namespaces.
kubectl create ns n1
kubectl create ns n2

# Install a KubeRay operator.
# Set `singleNamespaceInstall` to true in the `values.yaml` file.
# (path: helm-chart/kuberay-operator)
helm install kuberay-operator .

# Check ClusterRole.
kubectl get clusterrole | grep kuberay
# (nothing found)

# Check Role.
kubectl get role --all-namespaces | grep kuberay
#default       kuberay-operator                                 2023-10-15T05:18:03Z
#default       kuberay-operator-leader-election                 2023-10-15T05:18:03Z

# Install RayCluster in the `default`, `n1`, and `n2` namespaces.
helm install raycluster kuberay/ray-cluster --version 1.3.0
helm install raycluster kuberay/ray-cluster --version 1.3.0 -n n1
helm install raycluster kuberay/ray-cluster --version 1.3.0 -n n2

# KubeRay only creates a RayCluster in the `default` namespace.
kubectl get raycluster -A
# NAMESPACE   NAME                 DESIRED WORKERS   AVAILABLE WORKERS   STATUS   AGE
# default     raycluster-kuberay   1                 1                   ready    54s
# n1          raycluster-kuberay                                                  50s
# n2          raycluster-kuberay                                                  44s

用例 3:监控 Kubernetes 集群中的多个命名空间#

Watch multiple namespaces in the Kubernetes cluster

在用例 2 中,只有命名空间访问权限的用户会为每个命名空间部署一个单独的 KubeRay operator。这种方法会增加维护开销,尤其是在为每个部署实例升级版本时。用例 3 为多个命名空间创建 Role 和 RoleBinding,允许单个 KubeRay operator 监控多个命名空间。

  • 修改 values.yaml 文件中的 singleNamespaceInstallwatchNamespace 参数。

    # Set in the `value.yaml` file.
    singleNamespaceInstall: true
    
    # Set the namespaces list.
    watchNamespace:
      - n1
      - n2
    
# Create a Kubernetes cluster using Kind.
kind create cluster --image=kindest/node:v1.26.0

# Create namespaces.
kubectl create ns n1
kubectl create ns n2

# Install a KubeRay operator.
# Set `singleNamespaceInstall` and `watchNamespace` in the `values.yaml` file.
# (path: helm-chart/kuberay-operator)
helm install kuberay-operator .

# Check ClusterRole
kubectl get clusterrole | grep kuberay
# (nothing found)

# Check Role.
kubectl get role --all-namespaces | grep kuberay
#default       kuberay-operator-leader-election                 2023-10-15T05:34:27Z
#n1            kuberay-operator                                 2023-10-15T05:34:27Z
#n2            kuberay-operator                                 2023-10-15T05:34:27Z

# Install RayCluster in the `default`, `n1`, and `n2` namespaces.
helm install raycluster kuberay/ray-cluster --version 1.3.0
helm install raycluster kuberay/ray-cluster --version 1.3.0 -n n1
helm install raycluster kuberay/ray-cluster --version 1.3.0 -n n2

# KubeRay creates a RayCluster only in the `n1` and `n2` namespaces.
kubectl get raycluster -A
# NAMESPACE   NAME                 DESIRED WORKERS   AVAILABLE WORKERS   STATUS   AGE
# default     raycluster-kuberay                                                  74s
# n1          raycluster-kuberay   1                 1                   ready    70s
# n2          raycluster-kuberay   1                 1                   ready    67s