Last active
June 23, 2020 20:25
-
-
Save m-wild/39b188c5076634bb37bd8eaf28296787 to your computer and use it in GitHub Desktop.
Filebeat kubernetes configuration for logging to Graylog (acting as Logstash)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: counter | |
spec: | |
containers: | |
- name: count | |
image: busybox | |
args: [/bin/sh, -c, 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done'] | |
resources: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: filebeat-config | |
namespace: kube-system | |
labels: | |
k8s-app: filebeat | |
data: | |
filebeat.yml: |- | |
filebeat.inputs: | |
- type: container | |
paths: | |
- /var/log/containers/*.log | |
processors: | |
- add_kubernetes_metadata: | |
in_cluster: true | |
host: ${NODE_NAME} | |
matchers: | |
- logs_path: | |
logs_path: "/var/log/containers/" | |
# To enable hints based autodiscover, remove `filebeat.inputs` configuration and uncomment this: | |
#filebeat.autodiscover: | |
# providers: | |
# - type: kubernetes | |
# host: ${NODE_NAME} | |
# hints.enabled: true | |
# hints.default_config: | |
# type: container | |
# paths: | |
# - /var/log/containers/*${data.kubernetes.container.id}.log | |
processors: | |
- add_host_metadata: | |
output.logstash: | |
hosts: ["${LOGSTASH_HOST:logstash}:${LOGSTASH_PORT:5044}"] | |
--- | |
apiVersion: extensions/v1beta1 | |
kind: DaemonSet | |
metadata: | |
name: filebeat | |
namespace: kube-system | |
labels: | |
k8s-app: filebeat | |
spec: | |
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.3.1 | |
args: [ | |
"-c", "/etc/filebeat.yml", | |
"-e", | |
] | |
env: | |
- name: LOGSTASH_HOST | |
value: michaels-pc.fritz.box | |
- name: LOGSTASH_PORT | |
value: "5044" | |
- name: NODE_NAME | |
valueFrom: | |
fieldRef: | |
fieldPath: spec.nodeName | |
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: varlibdockercontainers | |
mountPath: /var/lib/docker/containers | |
readOnly: true | |
- name: varlog | |
mountPath: /var/log | |
readOnly: true | |
volumes: | |
- name: config | |
configMap: | |
defaultMode: 0600 | |
name: filebeat-config | |
- name: varlibdockercontainers | |
hostPath: | |
path: /var/lib/docker/containers | |
- name: varlog | |
hostPath: | |
path: /var/log | |
# 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 | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1beta1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: filebeat | |
subjects: | |
- kind: ServiceAccount | |
name: filebeat | |
namespace: kube-system | |
roleRef: | |
kind: ClusterRole | |
name: filebeat | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1beta1 | |
kind: ClusterRole | |
metadata: | |
name: filebeat | |
labels: | |
k8s-app: filebeat | |
rules: | |
- apiGroups: [""] # "" indicates the core API group | |
resources: | |
- namespaces | |
- pods | |
verbs: | |
- get | |
- watch | |
- list | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: filebeat | |
namespace: kube-system | |
labels: | |
k8s-app: filebeat | |
--- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment