Issues pushing kubernetes ingress-nginx logs using filebeat deamonset pods

Hello all,

We're facing issues pushing kubernetes ingress-nginx logs using filebeat deamonset pods.
using filebeat v6.2.4, 6.3.0, & 6.4.0.

please let us know if this is the correct configs to push only ingress-nginx pods logs to ELK, not all namespace pods.

filebeat.yml:
filebeat.config:
  prospectors:
    # Mounted `filebeat-prospectors` configmap:
    path: ${path.config}/prospectors.d/*.yml
    # Reload prospectors configs as they change:
    reload.enabled: false
  modules:
    path: ${path.config}/modules.d/*.yml
    # Reload module configs as they change:
    reload.enabled: false
  filebeat.autodiscover:
    providers:
     - type: docker
       templates:
         - condition:
             equals:
               docker.container.labels.io.kubernetes.container.name: "nginx-ingress-controller"
          config:
            - module: nginx
              access:
                input:
                  type: docker
                  containers.stream: stdout
                  containers.ids:
                    - "${data.docker.container.id}"
              error:
                input:
                  type: docker
                  containers.stream: stderr
                  containers.ids:
                    - "${data.docker.container.id}"
  processors:
   - drop_event:
      when.not:
        or:
          - contains:
               docker.container.labels.io.kubernetes.container.name: "nginx-ingress-controller"

  processors:
    - add_cloud_metadata:

  cloud.id: ${ELASTIC_CLOUD_ID}
  cloud.auth: ${ELASTIC_CLOUD_AUTH}

  output:
    logstash:
      hosts: ["elk.lktest1.com:5044"]

prospectors file;---

kubernetes.yml:
- type: docker
  containers:
    ids: "*"
    path: /var/lib/docker/containers
  fields:
    type: k8s_nginx_ingress_ctrls
  registry_file: "/var/lib/filebeat/registry"
  multiline:
    pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
    negate: true
    match: after
  processors:
    - add_kubernetes_metadata:
        in_cluster: true
        namespace: ingress-nginx

using deamonset to load above 2 configmap files.

errors getting from filebeat pods:

Exiting: error loading config file: yaml: line 17: did not find expected '-' indicator

Hi!

Seems like your configuration file cannot be parsed successfully. Could you try to fix the indentation in config part of filebeat.autodiscover?

See https://codebeautify.org/yaml-validator/cb421e58

Hi Chris,

Thanks for your reply!!
Indentations issues resolved.
could you please let me know the filebeat.autodiscover configs to filter out only the -- kubernetes.container.name: "nginx-ingress-controller"
to filter only ingress-nginx pods logs & push them to ELK, to view/organize them.

I tried out - https://gist.github.com/tkuther/b432827283f360293a87b5be49594f91
but this didn't helped me.

Thank you, Siva.

Hi,

what about something like the one below?

filebeat.autodiscover:
  providers:
    - type: kubernetes
      templates:
        - condition:
            equals:
              kubernetes.container.image: "nginx-ingress-controller"

https://www.elastic.co/guide/en/beats/filebeat/current/configuration-autodiscover.html#_kubernetes

@ChrsMark,

pods running fine except one pod, & unable to find logs in ELK after sometime, weird!!.

i'll share a zoom meeting link if you're willing to join, to wrap this issue in few minutes. if so, please drop a test mail to me - siva.krishna@lendingkart.com.

Hey,

let's keep this conversation in this thread for traceability and other community users' benefit.

In this regard, it would be helpful to provide details of your setup and any logs of the failing pod so as to isolate the problem.

Thank you!

sure, Thanks @ChrsMark !!

suspecting the issue with filebeat-config-ingress, now the pods are in error syncing state.
please check below all our deployments & let us know how to fix push only nginx-ingress-controller pods logs to our elk.
deamonset, we're using is:

{
  "kind": "DaemonSet",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "filebeat-ingress",
    "namespace": "logging",
    "labels": {
      "k8s-app": "filebeat",
      "kubernetes.io/cluster-service": "true"
    },
    "finalizers": [
      "foregroundDeletion"
    ]
  },
  "spec": {
    "selector": {
      "matchLabels": {
        "k8s-app": "filebeat",
        "kubernetes.io/cluster-service": "true"
      }
    },
    "template": {
      "metadata": {
        "creationTimestamp": null,
        "labels": {
          "k8s-app": "filebeat",
          "kubernetes.io/cluster-service": "true"
        }
      },
      "spec": {
        "volumes": [
          {
            "name": "config",
            "configMap": {
              "name": "filebeat-config-ingress",
              "defaultMode": 384
            }
          },
          {
            "name": "varlibdockercontainers",
            "hostPath": {
              "path": "/var/lib/docker/containers",
              "type": ""
            }
          },
          {
            "name": "logforwarderssl",
            "secret": {
              "secretName": "logforwarderssl",
              "defaultMode": 384
            }
          },
          {
            "name": "prospectors",
            "configMap": {
              "name": "filebeat-prospectors-ingress",
              "defaultMode": 384
            }
          },
          {
            "name": "data",
            "emptyDir": {}
          }
        ],
        "containers": [
          {
            "name": "filebeat",
            "image": "docker.elastic.co/beats/filebeat:6.3.0",
            "args": [
              "-c",
              "/etc/filebeat.yml",
              "-e"
            ],
            "env": [
              {
                "name": "ELASTICSEARCH_HOST",
                "value": "testelk.lk.com"
              },
              {
                "name": "ELASTIC_CLOUD_ID"
              },
              {
                "name": "ELASTIC_CLOUD_AUTH"
              },
              {
                "name": "POD_NAMESPACE",
                "valueFrom": {
                  "fieldRef": {
                    "apiVersion": "v1",
                    "fieldPath": "metadata.namespace"
                  }
                }
              }
            ],
            "resources": {
              "limits": {
                "memory": "200Mi"
              },
              "requests": {
                "cpu": "100m",
                "memory": "100Mi"
              }
            },
            "volumeMounts": [
              {
                "name": "config",
                "readOnly": true,
                "mountPath": "/etc/filebeat.yml",
                "subPath": "filebeat.yml"
              },
              {
                "name": "prospectors",
                "readOnly": true,
                "mountPath": "/usr/share/filebeat/prospectors.d"
              },
              {
                "name": "data",
                "mountPath": "/usr/share/filebeat/data"
              },
              {
                "name": "varlibdockercontainers",
                "readOnly": true,
                "mountPath": "/var/lib/docker/containers"
              },
              {
                "name": "logforwarderssl",
                "mountPath": "/certs/logforwarderssl"
              }
            ],
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "IfNotPresent",
            "securityContext": {
              "runAsUser": 0
            }
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "serviceAccountName": "filebeat",
        "serviceAccount": "filebeat",
        "securityContext": {},
        "schedulerName": "default-scheduler"
      }
    },
    "updateStrategy": {
      "type": "OnDelete"
    },
    "templateGeneration": 6,
    "revisionHistoryLimit": 10
  }
}

2 configmaps, we're using are:
filebeat-config-ingress:

filebeat.config:
 prospectors:
   # Mounted `filebeat-prospectors` configmap:
   path: ${path.config}/prospectors.d/*.yml
   # Reload prospectors configs as they change:
   reload.enabled: false
 modules:
   path: ${path.config}/modules.d/*.yml
   # Reload module configs as they change:
   reload.enabled: false
filebeat.autodiscover:
 providers:
   - type: kubernetes
     templates:
      - condition:
         equals:
           kubernetes.container.name: "nginx-ingress-controller"
        config:
           - module: nginx
             access:
               input:
                 type: docker
                 containers.ids:
                   - "${data.kubernetes.container.id}"
processors:
   - add_cloud_metadata:
   - add_docker_metadata:
   - add_kubernetes_metadata:

cloud.id: ${ELASTIC_CLOUD_ID}
cloud.auth: ${ELASTIC_CLOUD_AUTH}

output:
   logstash:
     hosts: ["testelk.lk.com:5044"]

filebeat-prospectors-ingress:

kubernetes.yml:
- type: docker
  containers:
    ids: "*"
    path: /var/lib/docker/containers
  fields:
    type: k8s_nginx_ingress_ctrls
  registry_file: "/var/lib/filebeat/registry"
  multiline:
    pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
    negate: true
    match: after
  processors:
    - add_kubernetes_metadata:
        in_cluster: true
        namespace: ${POD_NAMESPACE}

the last error logs of pod given below:

2019-11-13T07:13:15.323Z	INFO	add_cloud_metadata/add_cloud_metadata.go:301	add_cloud_metadata: hosting provider type detected as ec2, metadata={"availability_zone":"ap-south-1b","instance_id":"i-0d5d5bba0be1e449e","machine_type":"r3.xlarge","provider":"ec2","region":"ap-south-1"}
2019-11-13T07:13:15.324Z	INFO	instance/beat.go:275	filebeat stopped.
2019-11-13T07:13:15.324Z	ERROR	instance/beat.go:691	Exiting: error initializing publisher: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Exiting: error initializing publisher: error initializing processors: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Hi! Thank you for the feedback!

From the error you include the problem seems to be the add_docker_metadata processor. Since you are running Filebeat inside a pod I assume it cannot reach the docker daemon. Could you try and remove add_docker_metadata from Filebeat's config?

Thanks!

Hi Chris,

appreciated for your patience in replying. :slight_smile:
pods are running without errors, after removing add_docker_metadata from the configmap.

our main aim is, to push only the nginx-ingress-controller container logs to ELK, but It is not doing. could you please help here how to acheive that, to close the ticket.

found some index issues in logstash log file. digging further more.

[2019-11-13T10:38:10,910][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeat-2019.11.13", :_type=>"doc", :_routing=>nil}, 2019-11-13T10:38:07.552Z {name=filebeat-ingress-nwg5s} 2019-11-13 10:38:07.552 INFO [pool-9-thread-1] [,,,,,,] com.abc.admin.abc.schedulers.TaskScheduler 

t[2019-11-13T10:38:10,910][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeat-2019.11.13", :_type=>"doc", :_routing=>nil}, 2019-11-13T10:38:07.553Z {name=filebeat-ingress-nwg5s} 2019-11-13 10:38:07.553 ERROR [pool-9-thread-1] [,,,,,,]

[2019-11-13T12:52:49,390][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeat-2019.11.12", :_type=>"doc", :_routing=>nil}, 2019-11-12T12:16:03.089Z filebeat-ingress-t6z2z 2019-11-12 12:16:03.089  INFO [http-nio-9025-exec-205] [,,,,,,] org.crazycake.shiro.: Reading session with id : 3b973c3c-3a53-4681-a40b-527054297023 session: org.apache.shiro.session.mgt.SimpleSession,id=3b973-4681-a40b-527054297023], :response=>{"index"=>{"_index"=>"filebeat-2019.11.12", "_type"=>"doc", "_id"=>"AW5k0tZQvgXvqyg", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"object mapping for [host] tried to parse field [host] as object, but found a concrete value"}}}}
[2019-11-13T12:52:49,390][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeat-2019.11.12", :_type=>"doc", :_routing=>nil}, 2019-11-12T12:16:03.089Z filebeat-ingress-t6z2z 2019-11-12 12:16:03.089  INFO [http-nio-9025-exec-188] [,,,,,,] org.craze.ro.: Reading session with id : 3b973c3c-3a53-4681-a297023 session: org.apache.shiro.session.mgt.SimpleSession,id=3b973c3c-3a53-4681-a40b-527054297023], :response=>{"index"=>{"_index"=>"filebeat-2019.11.12", "_type"=>"doc", "_id"=>"AW5k0tZQvpwvqyh", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"object mapping for [host] tried to parse field [host] as object, but found a concrete value"}}}}

hi @Siva_Krishna,

Are you using add_host_metadata? It would look like it's clashing with some other system sending the host field.

Hi @exekias

nope, we're using below two. logs are not at all displayed when we used filebeat v6.30 image version, when using filebeat image v6.2.4 we could see some logs of ingress.
pointing the issues we're facing to make it clear.

  1. push only ingress-nginx-controller pods, but our filebeat configmaps pushing all namespaces pods logs with the grok pattern. which are unnecessary.
  2. Not all logs are not displaying in kibana for ingress nginx pods logs.
  3. facing some index related issues. shared earlier the error logs.
    we're using below versions of ELK.

logstash 5.6.16

sudo /usr/share/kibana/bin/kibana --version
5.6.16

$ /usr/share/elasticsearch/bin/elasticsearch --version
Version: 5.6.16, Build: 3a740d1/2019-03-13T15:33:36.565Z, JVM: 1.8.0_73

processors:
   - add_cloud_metadata:
   - add_kubernetes_metadata:

kindly help us.

@ChrsMark and Team,

Could you please provide any fix here!!

Hey!

It is not so clear what is the failing cause. The last output you provide is from Logstash, however could we focus on Filebeat's side first?

In this regard, could you please check and/or share the output of Filebeat's pod so as to confirm that Filebeat is able to parse the logs of ingress-nginx and if not what is the reason?

Thanks!

hey @ChrsMark,

I've resolved this issue using the configmap prospectors file configs, shared below.

earlier we are not adding these filters in processors in it. we were adding in filebeat-config-ingress configmap, which is wrong.

the correct configmap should be as below:

kubernetes.yml:
- type: docker
  containers:
    ids: "*"
    path: /var/lib/docker/containers
  fields:
    type: k8s_nginx_ingress_ctrls
  registry_file: "/var/lib/filebeat/registry"
  multiline:
    pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
    negate: true
    match: after
  processors:
    - add_kubernetes_metadata:
        in_cluster: true
        namespace: ${POD_NAMESPACE}
    - drop_event:
       when:
         not:
           regexp:
              kubernetes.container.name: "nginx-ingress-controller"
    - drop_event:
       when:
         not:
           regexp:
              kubernetes.container.name: "nginx-ingress-controller-internal"

index creation issue could be because of higher version of filebeat image in the deamonset configs. I was fixed when I use standard v6.2.4 image.

many thanks @ChrsMark & Team. :slight_smile: