LoginSignup
0
1

More than 5 years have passed since last update.

aws-workshop-for-kubernetesに従ってKubernetesのログをFluentdでCloudWatch Logsに連携するときのエラー対応方法

Last updated at Posted at 2018-07-21

aws-workshop-for-kubernetesに従ってFluentdからCloudWatch Logsにログ収集するとエラーが発生したので、対応方法を記載します。

発生したエラー

Aws::CloudWatchLogs::Errors::InvalidSequenceTokenExceptionというエラーが発生しました。

原因と対応方針

こちらの記事の通り、複数のログソースから単一のログストリームにデータを送信していることが原因です。

AWS公式ドキュメントの「CloudWatch Logs エージェントのリファレンス
」にも、このようなデータ収集はサポートしていないという記載があります。

同一または異なるホストの異なるログデータを同じログストリームに指定できますか。
複数のログソースから単一のログストリームにデータを送信する設定はサポートされていません。

aws-workshop-for-kubernetes/02-path-working-with-clusters/204-cluster-logging-with-EFK/templates/fluentd-configmap.yamlの関連部分は以下の通りです。

  output.conf: |
    <match **>
      # Plugin specific settings
      type cloudwatch_logs
      log_group_name kubernetes-logs
      log_stream_name fluentd-cloudwatch
      auto_create_stream true

      # Buffer settings
      buffer_chunk_limit 2M
      buffer_queue_limit 32
      flush_interval 10s
      max_retry_wait 30
      disable_retry_limit
      num_threads 8

    </match>

log_stream_nameが固定になっているのがエラーの原因です。

対応方法

fluent-plugin-cloudwatch-logsのREADMEを読むと、log_stream_nameにhostnameを入れることができると書かれています。

This plugin uses fluent-mixin-config-placeholders and you can use addtional variables such as %{hostname}, %{uuid}, etc. These variables are useful to put hostname in log_stream_name.

そこで、ConfigMapを以下の通り修正します。

  output.conf: |
    <match **>
      # Plugin specific settings
      type cloudwatch_logs
      log_group_name kubernetes-logs
      # ログストリーム名をhostごとに変える
      log_stream_name fluentd-cloudwatch-%{hostname}
      auto_create_stream true

      # Buffer settings
      buffer_chunk_limit 2M
      buffer_queue_limit 32
      flush_interval 10s
      max_retry_wait 30
      disable_retry_limit
      num_threads 8

    </match>

これで複数のログソースから単一のログストリームにデータを送信することによるエラーは発生しなくなります。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1