KubeSphere 事件系统

什么是 KubeSphere 事件系统

KubeSphere 事件系统使用户能够跟踪集群内部发生的事件,例如节点调度状态和镜像拉取结果。这些事件会被准确记录下来,并在 Web 控制台中显示具体的原因、状态和信息。要查询事件,用户可以快速启动 Web 工具箱,在搜索栏中输入相关信息,并有不同的过滤器(如关键字和项目)可供选择。事件也可以归档到第三方工具,例如 Elasticsearch、Kafka 或 Fluentd。

有关更多信息,请参见事件查询

在安装前启用事件系统

在 Linux 上安装

当您在 Linux 上安装多节点 KubeSphere 时,需要创建一个配置文件,该文件列出了所有 KubeSphere 组件。

  1. 基于在 Linux 上安装 KubeSphere 的教程,您需要创建一个默认文件 config-sample.yaml。通过执行以下命令修改该文件:

    1. vi config-sample.yaml

    备注

    如果您采用 All-in-One 安装,则不需要创建 config-sample.yaml 文件,因为可以直接创建集群。一般来说,All-in-One 模式是为那些刚接触 KubeSphere 并希望熟悉系统的用户而准备的。如果您想在该模式下启用事件系统(例如用于测试),请参考下面的部分,查看如何在安装后启用事件系统。

  2. 在该文件中,搜寻到 events,并将 enabledfalse 改为 true。完成后保存文件。

    1. events:
    2. enabled: true # Change "false" to "true"

    备注

    默认情况下,如果启用了事件系统,KubeKey 将安装内置 Elasticsearch。对于生产环境,如果您想启用事件系统,强烈建议在 config-sample.yaml 中设置以下值,尤其是 externalElasticsearchUrlexternalElasticsearchPort。在安装前提供以下信息后,KubeKey 将直接对接您的外部 Elasticsearch,不再安装内置 Elasticsearch。

    1. es: # Storage backend for logging, tracing, events and auditing.
    2. elasticsearchMasterReplicas: 1 # total number of master nodes, it's not allowed to use even number
    3. elasticsearchDataReplicas: 1 # total number of data nodes
    4. elasticsearchMasterVolumeSize: 4Gi # Volume size of Elasticsearch master nodes
    5. elasticsearchDataVolumeSize: 20Gi # Volume size of Elasticsearch data nodes
    6. logMaxAge: 7 # Log retention time in built-in Elasticsearch, it is 7 days by default.
    7. elkPrefix: logstash # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log
    8. externalElasticsearchUrl: # The URL of external Elasticsearch
    9. externalElasticsearchPort: # The port of external Elasticsearch
  3. 使用配置文件创建集群:

    1. ./kk create cluster -f config-sample.yaml

在 Kubernetes 上安装

在 Kubernetes 上安装 KubeSphere 的过程与教程在 Kubernetes 上安装 KubeSphere 中的说明大致相同,不同之处是需要先在 cluster-configuration.yaml 文件中启用事件系统(可选组件)。

  1. 下载 cluster-configuration.yaml 文件,然后打开并开始编辑。

    1. vi cluster-configuration.yaml
  2. 在该本地 cluster-configuration.yaml 文件中,搜寻到 events,并将 enabledfalse 改为 true,启用事件系统。完成后保存文件。

    1. events:
    2. enabled: true # Change "false" to "true"

    备注

    对于生产环境,如果您想启用事件系统,强烈建议在 cluster-configuration.yaml 中设置以下值,尤其是 externalElasticsearchUrlexternalElasticsearchPort。在安装前提供以下信息后,ks-installer 将直接对接您的外部 Elasticsearch,不再安装内置 Elasticsearch。

    1. es: # Storage backend for logging, tracing, events and auditing.
    2. elasticsearchMasterReplicas: 1 # total number of master nodes, it's not allowed to use even number
    3. elasticsearchDataReplicas: 1 # total number of data nodes
    4. elasticsearchMasterVolumeSize: 4Gi # Volume size of Elasticsearch master nodes
    5. elasticsearchDataVolumeSize: 20Gi # Volume size of Elasticsearch data nodes
    6. logMaxAge: 7 # Log retention time in built-in Elasticsearch, it is 7 days by default.
    7. elkPrefix: logstash # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log
    8. externalElasticsearchUrl: # The URL of external Elasticsearch
    9. externalElasticsearchPort: # The port of external Elasticsearch
  3. 执行以下命令开始安装:

    1. kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.1.0/kubesphere-installer.yaml
    2. kubectl apply -f cluster-configuration.yaml

在安装后启用事件系统

  1. admin 身份登录控制台。点击左上角的平台管理,选择集群管理

    集群管理

  2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration。点击结果查看其详细页面。

    信息

    自定义资源定义 (CRD) 允许用户在不新增 API 服务器的情况下创建一种新的资源类型,用户可以像使用其他 Kubernetes 原生对象一样使用这些自定义资源。

  3. 资源列表中,点击 ks-installer 右边的三个点,选择编辑配置文件

    编辑 YAML

  4. 在该 YAML 文件中,搜寻到 events,将 enabledfalse 改为 true。完成后,点击右下角的更新,保存配置。

    1. events:
    2. enabled: true # Change "false" to "true"

    备注

    默认情况下,如果启用了事件系统,将会安装内置 Elasticsearch。对于生产环境,如果您想启用事件系统,强烈建议在该 YAML 文件中设置以下值,尤其是 externalElasticsearchUrlexternalElasticsearchPort。在文件中提供以下信息后,KubeSphere 将直接对接您的外部 Elasticsearch,不再安装内置 Elasticsearch。

    1. es: # Storage backend for logging, tracing, events and auditing.
    2. elasticsearchMasterReplicas: 1 # total number of master nodes, it's not allowed to use even number
    3. elasticsearchDataReplicas: 1 # total number of data nodes
    4. elasticsearchMasterVolumeSize: 4Gi # Volume size of Elasticsearch master nodes
    5. elasticsearchDataVolumeSize: 20Gi # Volume size of Elasticsearch data nodes
    6. logMaxAge: 7 # Log retention time in built-in Elasticsearch, it is 7 days by default.
    7. elkPrefix: logstash # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log
    8. externalElasticsearchUrl: # The URL of external Elasticsearch
    9. externalElasticsearchPort: # The port of external Elasticsearch
  5. 您可以使用 Web Kubectl 工具执行以下命令来检查安装过程:

    1. kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

    提示

    您可以通过点击控制台右下角的锤子图标找到 Web Kubectl 工具。

验证组件的安装

如果您同时启用了日志系统和事件系统,可以在服务组件Logging 中查看事件系统状态。您可以看到如下图所示界面:

事件系统

如果只启用事件系统而不安装日志系统,则无法看到上图所示界面,因为不会显示 Logging 按钮。

执行以下命令来检查 Pod 的状态:

  1. kubectl get pod -n kubesphere-logging-system

如果组件运行成功,输出结果如下:

  1. NAME READY STATUS RESTARTS AGE
  2. elasticsearch-logging-data-0 1/1 Running 0 11m
  3. elasticsearch-logging-data-1 1/1 Running 0 6m48s
  4. elasticsearch-logging-discovery-0 1/1 Running 0 11m
  5. fluent-bit-ljlsl 1/1 Running 0 6m30s
  6. fluentbit-operator-5bf7687b88-85vxv 1/1 Running 0 11m
  7. ks-events-exporter-5cb959c74b-rc4lm 2/2 Running 0 7m1s
  8. ks-events-operator-7d46fcccc9-8vvsh 1/1 Running 0 10m
  9. ks-events-ruler-97f756879-lg65t 2/2 Running 0 7m1s
  10. ks-events-ruler-97f756879-ptbkr 2/2 Running 0 7m1s