Skip to content

Instantly share code, notes, and snippets.

@vjayajv
Created March 21, 2023 12:41
Show Gist options
  • Save vjayajv/88a29c6cf43b5b517723a23c865aba88 to your computer and use it in GitHub Desktop.
Save vjayajv/88a29c6cf43b5b517723a23c865aba88 to your computer and use it in GitHub Desktop.
---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
labels:
k8s-app: filebeat
data:
filebeat.yml: |-
filebeat.autodiscover:
providers:
- type: kubernetes
templates:
- condition:
contains:
kubernetes.container.image: "backend" # filters for image name containing 'backend' in it.
config:
- type: container
symlinks: true
paths:
- /var/log/containers/*-${data.kubernetes.container.id}.log
output.logstash:
hosts: ["${LOGSTASH_HOST}:${LOGSTASH_PORT}"]
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: filebeat
labels:
k8s-app: filebeat
spec:
selector:
matchLabels:
k8s-app: filebeat
template:
metadata:
labels:
k8s-app: filebeat
spec:
serviceAccountName: filebeat
terminationGracePeriodSeconds: 30
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: filebeat
image: docker.elastic.co/beats/filebeat:7.17.9
args: [
"-c", "/etc/filebeat.yml",
"-e",
]
env:
- name: LOGSTASH_HOST
value: "logstash"
- name: LOGSTASH_PORT
value: "5100"
securityContext:
runAsUser: 0
#If using Red Hat OpenShift uncomment this:
#privileged: true
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: varlogcontainers
mountPath: /var/log/containers
readOnly: true
- name: varlogpods
mountPath: /var/log/pods
readOnly: true
- name: dockersock
mountPath: "/var/run/docker.sock"
volumes:
# Bind previously defined ConfigMap
- name: dockersock
hostPath:
path: /var/run/docker.sock
- name: config
configMap:
defaultMode: 0600
name: filebeat-config
- name: varlogcontainers
hostPath:
path: /var/log/containers
- name: varlogpods
hostPath:
path: /var/log/pods
# 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-data
type: DirectoryOrCreate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment