{{< details >}}

  • Tier: 基础版,专业版,旗舰版
  • Offering: JihuLab.com,私有化部署
  • Status: Beta

{{< /details >}}

{{< history >}}

  • 引入于极狐GitLab 16.1,使用名为 environment_settings_to_graphqlkas_user_access, kas_user_access_projectexpose_authorized_cluster_agents功能标志。此功能处于beta
  • 功能标志 environment_settings_to_graphql 在极狐GitLab 16.2 中被移除。
  • 功能标志 kas_user_accesskas_user_access_projectexpose_authorized_cluster_agents 在极狐GitLab 16.2 中被移除。
  • 在极狐GitLab 16.10 中移动到环境详情页面中。

{{< /history >}}

使用 Kubernetes 仪表板通过直观的界面来了解集群的状态。仪表板适用于所有已连接的 Kubernetes 集群,无论是通过 CI/CD 或 GitOps 部署的。

Dashboard showing the status of Kubernetes pods and services.

配置仪表板

{{< history >}}

  • 通过命名空间进行资源过滤引入于极狐GitLab 16.2,使用名为 kubernetes_namespace_for_environment功能标志。默认禁用。
  • 通过命名空间过滤资源在极狐GitLab 16.3 中默认启用。功能标志 kubernetes_namespace_for_environment 被移除。
  • 选择相关的 Flux 资源引入于极狐GitLab 16.3,使用名为 flux_resource_for_environment 的功能标志。
  • 选择相关的 Flux 资源在极狐GitLab 16.4 中 GA。功能标志 flux_resource_for_environment 被移除。

{{< /history >}}

配置仪表板以在给定环境中使用。你可以为已存在的环境配置仪表板,或者在创建环境时添加一个。

条件:

  • 极狐GitLab 的 Kubernetes 代理已安装并为环境项目或其父群组配置了 user_access

{{< tabs >}}

{{< tab title=”The environment already exists” >}}

  1. 在左侧边栏中,选择 搜索或转到 并找到你的项目。
  2. 选择 运维 > 环境
  3. 选择要与 Kubernetes 代理关联的环境。
  4. 选择 Edit
  5. 选择一个极狐GitLab 的 Kubernetes 代理。
  6. 可选。从 Kubernetes 命名空间 下拉列表中选择一个命名空间。
  7. 可选。从 Flux 资源 下拉列表中选择一个 Flux 资源。
  8. 选择 保存

{{< /tab >}}

{{< tab title=”The environment doesn’t exist” >}}

  1. 在左侧边栏中,选择 搜索或转到 并找到你的项目。
  2. 选择 运维 > 环境
  3. 选择 New environment
  4. 完成 Name 字段。
  5. 选择一个极狐GitLab 的 Kubernetes 代理。
  6. 可选。从 Kubernetes 命名孔吉娜 下拉列表中选择一个命名空间。
  7. 可选。从 Flux 资源 下拉列表中选择一个 Flux 资源。
  8. 选择 保存

{{< /tab >}}

{{< /tabs >}}

为动态环境配置仪表板

{{< history >}}

  • 引入于极狐GitLab 17.6。

{{< /history >}}

要为动态环境配置仪表板:

  • 在你的 .gitlab-ci.yml 文件中指定代理。必须指定代理配置项目的完整路径,后跟一个冒号和代理名称。

例如:

deploy_review_app:
  stage: deploy
  script: make deploy
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    kubernetes:
      agent: path/to/agent/project:agent-name

有关更多信息,请参阅 CI/CD YAML 语法参考

查看仪表板

{{< history >}}

  • Kubernetes watch API 集成引入于极狐GitLab 16.6,使用名为 k8s_watch_api功能标志。默认禁用。
  • Kubernetes watch API 集成在极狐GitLab 16.7 中默认启用。
  • 在极狐GitLab 17.1 中 GA。功能标志 k8s_watch_api 被移除。

{{< /history >}}

查看仪表板以了解已连接集群的状态。如果启用了 k8s_watch_api 特性标志,Kubernetes 资源的状态和 Flux 调解实时更新。

要查看已配置的仪表板:

  1. 在左侧边栏中,选择 搜索或转到 并找到你的项目。
  2. 选择 运维 > 环境
  3. 选择与 Kubernetes 代理关联的环境。
  4. 选择 Kubernetes 概览 选项卡。

会显示一个 pod 列表。选择一个 pod 查看其详细信息。

Flux 同步状态

{{< history >}}

  • 引入于极狐GitLab 16.3.
  • 自定义 Flux 资源名称引入于极狐GitLab 16.3,使用名为 flux_resource_for_environment功能标志
  • 自定义 Flux 资源名称引入于极狐GitLab 16.4 中 GA。功能标志 flux_resource_for_environment 被移除。

{{< /history >}}

你可以从仪表板查看 Flux 部署的同步状态。要显示部署状态,仪表板必须能够检索 KustomizationHelmRelease 资源,这需要为环境配置命名空间。

极狐GitLab 在环境设置中的 Flux 资源 下拉列表中搜索指定的 KustomizationHelmRelease 资源。

仪表板会显示以下状态徽章之一:

状态 描述
Reconciled 部署已成功与其环境调解。
Reconciling 正在进行调解。
Stalled 调解因错误卡住,无法在没有人为干预的情况下解决。
Failed 部署无法调解,因为出现不可恢复的错误。
Unknown 无法检索部署的同步状态。
Unavailable 无法检索 KustomizationHelmRelease 资源。

触发 Flux 调解

{{< history >}}

  • 引入于极狐GitLab 17.3。

{{< /history >}}

你可以手动调解部署与其 Flux 资源。

要触发调解:

  1. 在仪表板上,选择 Flux 部署的同步状态徽章。
  2. 选择 Actions ({{< icon name=”ellipsis_v” >}}) > Trigger reconciliation ({{< icon name=”retry” >}})。

暂停或恢复 Flux 调解

{{< history >}}

  • 引入于极狐GitLab 17.5。

{{< /history >}}

你可以通过 UI 手动暂停或恢复 Flux 调解。

要暂停或恢复调解:

  1. 在仪表板上,选择 Flux 部署的同步状态徽章。
  2. 选择 Actions ({{< icon name=”ellipsis_v” >}}),然后选择以下选项之一:
    • Suspend reconciliation ({{< icon name=”stop” >}}) 暂停 Flux 调解。
    • Resume reconciliation ({{< icon name=”play” >}}) 恢复 Flux 调解。

查看 pod 日志

{{< history >}}

  • 引入于极狐GitLab 17.2。

{{< /history >}}

当你想快速了解和排查环境中的问题时,可以从已配置的仪表板查看 pod 日志。你可以查看 pod 中每个容器的日志。

  • 选择 View logs,然后选择要查看日志的容器。

你还可以从 pod 详细信息中查看 pod 日志。

删除 pod

{{< history >}}

  • 引入于极狐GitLab 17.3。

{{< /history >}}

要重启失败的 pod,请从 Kubernetes 仪表板中删除它。

要删除 pod:

  1. Kubernetes 概览 选项卡中,找到要删除的 pod。
  2. 选择 Actions ({{< icon name=”ellipsis_v” >}}) > Delete pod ({{< icon name=”remove” >}})。

你还可以从 pod 详细信息中删除 pod。

详细仪表板

{{< history >}}

  • 引入于极狐GitLab 16.4,使用名为 k8s_dashboard功能标志。默认禁用。
  • 在极狐GitLab 为一部分用户在 JihuLab.com 上启用。

{{< /history >}}

{{< alert type=”flag” >}}

此功能的可用性由特性标志控制。更多信息,请查看历史记录。此功能可用于测试,但尚未准备好用于生产环境。

{{< /alert >}}

详细仪表板提供以下 Kubernetes 资源的信息:

  • Pods
  • Services
  • Deployments
  • ReplicaSets
  • StatefulSets
  • DaemonSets
  • Jobs
  • CronJobs

每个仪表板显示资源列表及其状态、命名空间和年龄。你可以选择一个资源以打开抽屉,查看更多信息,包括标签和 YAML 格式的状态、注释和规范。

Dashboard with detailed information about the connected cluster.

查看详细仪表板

条件:

  • 极狐GitLab 的 Kubernetes 代理已配置并与环境项目或其父群组共享,使用 user_access 关键字。

详细仪表板没有从侧边栏导航链接。要查看详细仪表板:

  1. 找到你的 Kubernetes 代理 ID:
    1. 在左侧边栏中,选择 搜索或转到 并找到你的项目。
    2. 选择 Operate > Kubernetes clusters
    3. 复制要访问的代理的数字 ID。
  2. 转到以下 URL 之一,将 <agent_id> 替换为你的代理 ID:

    资源类型 URL
    Pods https://myinstance.gitlab.com/-/kubernetes/<agent_id>/pods
    Services https://myinstance.gitlab.com/-/kubernetes/<agent_id>/services
    Deployments https://myinstance.gitlab.com/-/kubernetes/<agent_id>/deployments
    ReplicaSets https://myinstance.gitlab.com/-/kubernetes/<agent_id>/replicaSets
    StatefulSets https://myinstance.gitlab.com/-/kubernetes/<agent_id>/statefulSets
    DaemonSets https://myinstance.gitlab.com/-/kubernetes/<agent_id>/daemonSets
    Jobs https://myinstance.gitlab.com/-/kubernetes/<agent_id>/jobs
    CronJobs https://myinstance.gitlab.com/-/kubernetes/<agent_id>/cronJobs

故障排除

在使用 Kubernetes 仪表板时,你可能会遇到以下问题。

用户无法在 API 组中列出资源

你可能会收到一个错误,指出 Error: services is forbidden: User "gitlab:user:<user-name>" cannot list resource "<resource-name>" in API group "" at the cluster scope

此错误发生在用户不允许在 Kubernetes RBAC 中执行指定操作时。

要解决此问题,请检查你的 RBAC 配置。如果 RBAC 配置正确,请联系你的 Kubernetes 管理员。

极狐GitLab 代理下拉列表为空

当你配置新环境时,即使已经配置了 Kubernetes 集群,极狐GitLab 代理 下拉列表可能为空。

要填充 极狐GitLab 代理 下拉列表,请使用 user_access 关键字为代理授予 Kubernetes 访问权限。