LoginSignup
1
2

More than 5 years have passed since last update.

LogglyにKubernetes上のコンテナのログを送る

Last updated at Posted at 2018-01-24

ここが元ネタ です。Kubernetes上に構築した全てのコンテナのログを Loggly に送信します。

仕組みとしては fluentd コンテナ (DaemonSet) をデプロイして、各Agentノードの /var/lib/docker/containers/ 以下のコンテナログを自動的に Loggly へ送信して貰う感じです。

Loggly のカスタマートークンを発行する

多分、アカウントを作った時点で既に1つが発行済です。

tokens.png

fluentd (daemonset) をデプロイする

次の DaemonSet をデプロイします。Image の実態は fluentd で、k8s標準のfluentd Imageを元にしている ようです。送信先のURLだけ変えたそうな。

環境変数 LOGGLY_URL のところを各自の環境に合わせて変えて下さい。

  • https://logs-01.loggly.com/inputs/{{ カスタマートークン }}/tag/{{ タグ }}
    • {{ カスタマートークン }}
      • → 前述の発行済みトークンです
    • {{ タグ }}
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: fluentd-es-v1.20
  namespace: kube-system
  labels:
    k8s-app: fluentd-es
    kubernetes.io/cluster-service: "true"
    version: v1.20
spec:
  template:
    metadata:
      labels:
        k8s-app: fluentd-es
        kubernetes.io/cluster-service: "true"
        version: v1.20
    spec:
      containers:
      - name: fluentd-es
        image: garland/kubernetes-fluentd-loggly:1.0
        command:
          - '/bin/sh'
          - '-c'
          - '/usr/sbin/td-agent 2>&1 >> /var/log/fluentd.log'
        env:
          - name: LOGGLY_URL
            value: "https://logs-01.loggly.com/inputs/{{ カスタマートークン }}/tag/{{ タグ }}"
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
      # nodeSelector:
      #   alpha.kubernetes.io/fluentd-ds-ready: "true"
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers

簡単ですね (^o^)

1
2
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
1
2