GitLab agent for Kubernetes 配置
- Tier: Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
当你 设置 workspace 基础设施 时, 你必须配置一个 GitLab agent for Kubernetes 来支持 workspaces。本指南假设 GitLab agent 已经安装在 Kubernetes 集群中。
先决条件:
-
你必须完成 教程:设置 GitLab agent for Kubernetes 中的设置步骤。
-
agent 配置必须启用
remote_development模块,并且该模块的必需字段必须正确设置。如果你在有 active workspaces 的 agent 上禁用
remote_development模块, 这些 workspaces 将变得不可用。更多信息,请参见 workspace 设置。 -
agent 必须被允许在某个组中用于创建 workspaces。在创建 workspace 时,用户可以选择与 workspace 项目任何父组关联的允许的 agent。
-
workspace 创建者必须对 agent 的项目拥有 Developer 角色。
在组中为创建 workspace 授权 agent
新的授权策略取代了 传统授权策略。 组所有者和管理员可以控制哪些集群 agent 在他们的组中托管 workspaces。
例如,如果你的 workspace 项目路径是 top-level-group/subgroup-1/subgroup-2/workspace-project,你可以使用为 top-level-group、subgroup-1 或 subgroup-2 组配置的任何 agent。
%%{init: {'theme':'neutral'}}%%
graph TD;
classDef active fill:lightgreen, stroke:#green, color:green, stroke-width:1px;
topGroup[顶级组,允许的 Agent 1]
subgroup1[子组 1,允许的 Agent 2]
subgroup2[子组 2,允许的 Agent 3]
wp(Workspace 项目,Agent 1、2 和 3 都可用)
topGroup --> subgroup1
subgroup1 --> subgroup2
subgroup2 --> wp
class wp active;
如果你为特定组(例如 subgroup-1)允许集群 agent,
它可用于在该组下的所有项目中创建 workspaces。
请仔细考虑允许组的作用域,因为它决定了集群 agent 可以托管 workspaces 的位置。
在组中为 workspace 允许集群 agent
先决条件:
- 你必须 设置 workspace 基础设施。
- 你必须对实例有管理员访问权限,或者拥有该组的 Owner 角色。
要在组中为 workspace 允许集群 agent:
- 在左侧边栏,选择 Search or go to 并找到你的组。
- 在左侧边栏,选择 Settings > Workspaces。
- 在 Group agents 部分,选择 All agents 选项卡。
- 从可用 agent 列表中,找到状态为 Blocked 的 agent,然后选择 Allow。
- 在确认对话框中,选择 Allow agent。
GitLab 将所选 agent 的状态更新为 Allowed,并在 Allowed agents 选项卡中显示该 agent。
从组中移除允许的集群 agent
先决条件:
- 你必须 设置 workspace 基础设施。
- 你必须对实例有管理员访问权限,或者拥有该组的 Owner 角色。
要从组中移除允许的集群 agent:
- 在左侧边栏,选择 Search or go to 并找到你的组。
- 在左侧边栏,选择 Settings > Workspaces。
- 在 Group agents 部分,选择 Allowed agents 选项卡。
- 从允许的 agent 列表中,找到你想要移除的 agent,然后选择 Block。
- 在确认对话框中,选择 Block agent。
GitLab 将所选 agent 的状态更新为 Blocked,并从 Allowed agents 选项卡中移除该 agent。
从组中移除允许的集群 agent 不会立即停止使用该 agent 的运行中的 workspaces。运行中的 workspaces 会在自动终止或手动停止时停止。
在实例上为 workspace 允许集群 agent
先决条件:
- 你必须 设置 workspace 基础设施。
- 你必须拥有 启用了 remote development 的 agent。
- 你必须对实例有管理员访问权限。
要在实例上为 workspace 允许集群 agent:
- 在左侧边栏底部,选择 Admin。
- 在左侧边栏,选择 Settings > General。
- 展开 Available agents for workspaces。
- 从启用了 workspaces 的 agent 列表中,找到你想要允许的 agent,然后选择可用性开关。
从实例上移除允许的集群 agent
先决条件:
- 你必须对实例有管理员访问权限。
要从实例上移除允许的集群 agent:
- 在左侧边栏底部,选择 Admin。
- 在左侧边栏,选择 Settings > General。
- 展开 Available agents for workspaces。
- 从允许的 agent 列表中,找到你想要移除的 agent,然后清除可用性开关。
从实例上移除允许的集群 agent 不会立即停止使用该 agent 的运行中的 workspaces。运行中的 workspaces 会在自动终止或手动停止时停止。
传统 agent 授权策略
在 GitLab 17.1 及更早版本中,agent 在组中的可用性不是创建 workspaces 的先决条件。 如果以下两个条件都为真,你可以使用 workspace 项目顶级组中的任何 agent 来创建 workspace:
- remote development 模块已启用。
- 你对顶级组至少拥有 Developer 角色。
例如,如果你的 workspace 项目路径是 top-level-group/subgroup-1/subgroup-2/workspace-project,
你可以使用 top-level-group 中及其任何子组中配置的任何 agent。
使用 remote development 配置用户访问
你可以配置 user_access 模块,使用你的 GitLab 凭据访问连接的 Kubernetes 集群。
此模块的配置和运行独立于 remote_development 模块。
在同一 agent 中同时配置 user_access 和 remote_development 时要小心。
remote_development 集群将用户凭据(如个人访问令牌)作为 Kubernetes Secrets 进行管理。
user_access 中的任何错误配置都可能导致这些私人数据通过 Kubernetes API 被访问。
有关配置 user_access 的更多信息,请参见
配置 Kubernetes 访问。