Created
March 19, 2021 07:30
-
-
Save alphajc/9f8eb7f337323287a5121464c025b77d to your computer and use it in GitHub Desktop.
This file contains hidden or 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: |- | |
# 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.enabled: true | |
hints.default_config: | |
type: container | |
paths: | |
- /var/log/containers/*${data.kubernetes.container.id}.log | |
processors: | |
- add_cloud_metadata: | |
providers: | |
- qcloud | |
- add_host_metadata: | |
netinfo.enabled: false | |
- copy_fields: | |
fields: | |
- {from: "kubernetes.labels.app", to: "container.service"} | |
- {from: "kubernetes.labels.project", to: "container.service"} | |
ignore_missing: true | |
fail_on_error: false | |
- convert: | |
fields: | |
- {from: "kubernetes.container.name", to: "container.name", type: "string"} | |
ignore_missing: true | |
fail_on_error: false | |
- drop_fields: | |
fields: | |
- kubernetes.node | |
- kubernetes.container | |
cloud.id: ${ELASTIC_CLOUD_ID} | |
cloud.auth: ${ELASTIC_CLOUD_AUTH} | |
setup: | |
template: | |
name: "clogs" | |
type: "index" | |
pattern: "clogs-*" | |
settings: | |
index.number_of_shards: 1 | |
index.number_of_replicas: 1 | |
ilm: | |
enabled: auto | |
rollover_alias: "clogs" | |
pattern: "{now/d}" | |
policy_name: "clogs" | |
output.elasticsearch: | |
hosts: ['${ELASTICSEARCH_HOST:elasticsearch}:${ELASTICSEARCH_PORT:9200}'] | |
username: ${ELASTICSEARCH_USERNAME} | |
password: ${ELASTICSEARCH_PASSWORD} | |
indices: | |
- index: "clogs-%{[container.service]}-%{+yyyy.MM.dd}" | |
when.has_fields: ['container.service'] | |
- index: "clogs-%{+yyyy.MM.dd}" | |
--- | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: filebeat | |
namespace: kube-system | |
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.11.2 | |
args: [ | |
"-c", "/etc/filebeat.yml", | |
"-e", | |
] | |
env: | |
- name: ELASTICSEARCH_HOST | |
value: 10.1.128.86 | |
- name: ELASTICSEARCH_PORT | |
value: "9200" | |
- name: ELASTICSEARCH_USERNAME | |
value: logger | |
- name: ELASTICSEARCH_PASSWORD | |
value: Ah!7T0I*jw%^ | |
- name: ELASTIC_CLOUD_ID | |
value: | |
- name: ELASTIC_CLOUD_AUTH | |
value: | |
- 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: 0640 | |
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: | |
# When filebeat runs as non-root user, this directory needs to be writable by group (g+w). | |
path: /var/lib/filebeat-data | |
type: DirectoryOrCreate | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
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/v1 | |
kind: ClusterRole | |
metadata: | |
name: filebeat | |
labels: | |
k8s-app: filebeat | |
rules: | |
- apiGroups: [""] # "" indicates the core API group | |
resources: | |
- namespaces | |
- pods | |
- nodes | |
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