website/content/zh/docs/pluggable-components/events.md
2020-12-08 14:19:04 +08:00

9.0 KiB
Raw Blame History

title keywords description linkTitle weight
KubeSphere 事件系统 Kubernetes, events, KubeSphere, k8s-events 如何启用 KubeSphere 事件 KubeSphere 事件系统 6500

什么是 KubeSphere 事件系统

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

有关更多信息,请参见审计日志查询

在安装前启用事件系统

在 Linux 上安装

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

    vi config-sample.yaml
    

    {{< notice note >}} 如果采用 All-in-one 安装,则不需要创建config-sample.yaml文件因为可以直接创建集群。一般来说All-in-one 模式是为那些刚刚接触 KubeSphere 并希望熟悉系统的用户准备的,如果您想在这个模式下启用事件(比如出于测试的目的),可以参考下面的部分,看看安装后如何启用事件系统。 {{</ notice >}}

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

    events:
        enabled: true # Change "false" to "true"
    

    {{< notice note >}} 默认情况下如果启用了审计功能KubeKey 将在内部安装 Elasticsearch。对于生产环境如果你想启用事件强烈建议你在 config-sample.yaml 中设置以下值,尤其是externalElasticsearchUrlexternalElasticsearchPort。一旦你在安装前提供以下信息KubeKey 将直接整合你的外部 Elasticsearch而不是安装一个内部 Elasticsearch。 {{</ notice >}}

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

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

在 Kubernetes 上安装

在已有 Kubernetes 集群上安装 KubeSphere 时,需要部署 ks-installer 的两个 yaml 文件,如下面所示。

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

    vi cluster-configuration.yaml
    
  2. 在这个本地cluster-configuration.yaml文件中,搜寻到events,并将enabledfalse改为true,启用它们。完成后保存文件。

    events:
        enabled: true # Change "false" to "true"
    

    {{< notice note >}} 默认情况下如果启用了事件功能ks-installer 会在内部安装 Elasticsearch。对于生产环境如果你想启用事件强烈建议你在 cluster-configuration.yaml 中设置以下值,尤其是externalElasticsearchUrlexternalElasticsearchPort。当你在安装前提供以下信息时ks-installer 将直接整合你的外部 Elasticsearch而不是安装内部 Elasticsearch。 {{</ notice >}}

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

    kubectl apply -f cluster-configuration.yaml
    

在安装后启用事件

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

    集群管理

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

    {{< notice info >}} 自定义资源定义CRD允许用户在不增加额外的 API 服务器的情况下创建一种新的资源类型,用户可以像使用其它 Kubernetes 内置对象一样使用这些自定义资源。 {{</ notice >}}

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

    编辑 YAML

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

    events:
        enabled: true # Change "false" to "true"
    

    {{< notice note >}} 默认情况下如果启用了事件Elasticsearch 将在内部安装。对于生产环境,如果你想启用审计,强烈建议你在这个 YAML 文件中设置以下值,尤其是externalElasticsearchUrlexternalElasticsearchPort。一旦你提供了以下信息KubeSphere 将直接整合你的外部 Elasticsearch而不是安装一个内部 Elasticsearch。 {{</ notice >}}

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

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

    {{< notice tip >}} 您可以通过点击控制台右下角的锤子图标找到 Kubectl 工具。 {{</ notice >}}

验证组件的安装

{{< tabs >}}

{{< tab "在仪表板中验证组件的安装" >}}

如果您同时启用了日志和事件,可以在服务组件Logging 中查看事件服务状态,可以看到如下图片:

events

如果只启用事件而不安装日志,则无法看到上面的图片,因为 Loggiing 按钮不会显示。

{{</ tab >}}

{{< tab "通过 kubectl 验证组件的安装" >}}

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

kubectl get pod -n kubesphere-logging-system

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

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

{{</ tab >}}

{{</ tabs >}}