导出日志

本页面适用于基础架构运维者

配置 fluent-bit 附加输出

除了在集群中运行的 Loki 之外,您还可以将日志导出到其他目标位置。请参阅支持的平台列表。此设置可以按集群配置或进行全局配置。

全局配置

  1. anthos-management-center 命名空间中创建一个带有 logmon: system_logs 标签的 configmap。额外的输出配置与 fluent-bit 输出插件具有相同的语法,应添加到 output.conf 文件中的 data 字段下。请参阅示例配置文件

    apiVersion: v1
    kind: ConfigMap
    metadata:
      # The name should match the configmap name specified in step 3.
      name: <customized-system-logs-fluent-bit-output-config>
      # Don't change the namespace
      namespace: anthos-management-center
      labels:
        # This label is required.
        logmon: system_logs
    data:
      # The file name must be output.conf
      output.conf: |
        # Add a customized fluent-bit output plugin configuration here
    
  2. 运行以下命令,在命令行编辑器中打开您的 Observability 自定义资源:

    kubectl --kubeconfig=ADMIN_OIDC_KUBECONFIG -n anthos-management-center edit observability default
    
  3. Observability 自定义资源中的 spec/logging 字段下添加 additionalSink 字段。

    apiVersion: managementcenter.anthos.cloud.google.com/v1alpha1
    kind: Observability
    metadata:
      # Don't change the name
      name: default
      # Don't change the namespace
      namespace: anthos-management-center
    spec:
      enabled: true
      logging:
        additionalSink:
          fluentbitConfigMaps:
          # The name should match the configmap name created in step 1.
          - "<customized-system-logs-fluent-bit-output-config>"
          # Scheme: []v1.VolumeMount. Add volumeMounts if necessary
          volumeMounts:
          - ...
          - ...
          # Scheme: []v1.Volume. Add volumes if necessary
          volumes:
          - ...
          - ...
    
  4. 如需保存对 Observability 自定义资源所做的更改,请保存并退出命令行编辑器。

按集群配置

  1. 通过将集群名称添加到 Observability 自定义资源中的 spec/logging/additionalSink/clusterSelector/exclude 列表,可以从全局配置中排除集群。

    apiVersion: managementcenter.anthos.cloud.google.com/v1alpha1
    kind: Observability
    metadata:
      # Don't change the name
      name: default
      # Don't change the namespace
      namespace: anthos-management-center
    spec:
      enabled: true
      logging:
        additionalSink:
          clusterSelector:
            exclude:
            - cluster-name
          ...
    
  2. kube-system 命名空间中创建一个带有 logmon: system_logs 标签的 configmap。额外的输出配置与 fluent-bit 输出插件具有相同的语法,应添加到 output.conf 文件中的 data 字段下。请参阅示例配置文件

    apiVersion: v1
    kind: ConfigMap
    metadata:
      # The name should match the configmap name specified in step 3.
      name: <customized-system-logs-fluent-bit-output-config>
      # Don't change the namespace
      namespace: kube-system
      labels:
        # This label is required.
        logmon: system_logs
    data:
      # The file name must be output.conf
      output.conf: |
        # Add a customized fluent-bit output plugin configuration here
    
  3. 运行以下命令,在命令行编辑器中打开您的 LogMon 自定义资源:

    kubectl --kubeconfig=ADMIN_OIDC_KUBECONFIG -n kube-system edit logmon logmon-default
    
  4. LogMon 自定义资源中的 spec/system_logs/outputs 字段下添加 additionalOutput 字段。

    apiVersion: addons.gke.io/v1alpha1
    kind: Logmon
    metadata:
      # Don't change the name
      name: logmon-default
      # Don't change the namespace
      namespace: kube-system
    spec:
      system_logs:
        outputs:
          additionalOutput:
            fluentbitConfigmaps:
            # The name should match the configmap name created in step 1.
            - "<customized-system-logs-fluent-bit-output-config>"
            # Scheme: []v1.VolumeMount. Add volumeMounts if necessary
            volumeMounts:
            - ...
            - ...
            # Scheme: []v1.Volume. Add volumes if necessary
            volumes:
            - ...
            - ...
    
  5. 如需保存对 LogMon 自定义资源所做的更改,请保存并退出命令行编辑器。