1

I need to receive all container logs using Filebeat autodiscover. When I deployed Filebeat to Kubernetes without using helm, I got all the container logs in the first attempt. I want to do the same with helm. However, because I applied a very complex configuration, I cannot receive the log files from all containers, PodList returns just this node container log. I can't find out how I did it on my first try. The first option that came to my mind was to give the serviceaccount a cluster-admin role. But I could not access all the log files again when I tried it.

How to access all container log list using Filebeat Autodiscover (deamonset is a bad solution)?

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-config
  namespace: bau
  labels:
    k8s-app: filebeat
data:
  filebeat.yml: |-
    filebeat.autodiscover:
      providers:
        - type: kubernetes
          templates:
            - condition:
                equals:
                  kubernetes.namespace: bau
              config:
                - type: docker
                  containers.ids:
                    - "${data.kubernetes.container.id}"
    output.elasticsearch:
      hosts: ['${ELASTICSEARCH_HOST:elasticsearch}:${ELASTICSEARCH_PORT:9200}']
    setup.template.settings:
      index.number_of_shards: 5
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: filebeat
subjects:
- kind: ServiceAccount
  name: filebeat
  namespace: bau
roleRef:
  kind: ClusterRole 
  name: cluster-admin 
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: filebeat
  namespace: bau
  labels:
    k8s-app: filebeat
---
apiVersion: v1
kind: Pod
metadata:
  name: filebeat
  namespace: bau
spec:
  serviceAccountName: filebeat
  containers:
  - name: filebeat
    image: "10.6.155.20:5000/filebeat:6.5.3"
    args: [
      "-c", "/etc/filebeat.yml",
      "-e",
    ]
    env:
    - name: ELASTICSEARCH_HOST
      value: bau-sla-elasticsearch
    - name: ELASTICSEARCH_PORT
      value: "9200"
    securityContext:
      runAsUser: 0
      fsGroup: 2000
    resources:
      limits:
        memory: 200Mi
      requests:
        cpu: 100m
        memory: 100Mi
    volumeMounts:
    - name: config
      mountPath: /etc/filebeat.yml
      readOnly: true
      subPath: filebeat.yml
    - name: data
      mountPath: /usr/share/filebeat/data
    - name: varlibdockercontainers
      mountPath: /var/lib/docker/containers
      readOnly: true
  volumes:
  - name: config
    configMap:
      defaultMode: 0600
      name: filebeat-config
  - name: varlibdockercontainers
    hostPath:
      path: /var/lib/docker/containers
  # data folder stores a registry of read status for all files, so we don't send everything again on a Filebeat pod restart
  - name: data
    hostPath:
      path: /var/lib/filebeat/bau
      type: DirectoryOrCreate
---

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.