Created
November 5, 2023 13:40
-
-
Save iml1111/a86916de4a6dcc0746a2a2c1fd750609 to your computer and use it in GitHub Desktop.
EKS Workshop: Container Insight Daemon-sets
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
# {{cluster_name}} | |
# {{region_name}} = ap-northeast-2 | |
# {{http_server_toggle}} = On | |
# {{http_server_port}} = 2020 | |
# {{read_from_head}} = Off | |
# {{read_from_tail}} = On | |
# create amazon-cloudwatch namespace | |
apiVersion: v1 | |
kind: Namespace | |
metadata: | |
name: amazon-cloudwatch | |
labels: | |
name: amazon-cloudwatch | |
--- | |
# create cwagent service account and role binding | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: cloudwatch-agent | |
namespace: amazon-cloudwatch | |
--- | |
kind: ClusterRole | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: cloudwatch-agent-role | |
rules: | |
- apiGroups: [""] | |
resources: ["pods", "nodes", "endpoints"] | |
verbs: ["list", "watch"] | |
- apiGroups: ["apps"] | |
resources: ["replicasets"] | |
verbs: ["list", "watch"] | |
- apiGroups: ["batch"] | |
resources: ["jobs"] | |
verbs: ["list", "watch"] | |
- apiGroups: [""] | |
resources: ["nodes/proxy"] | |
verbs: ["get"] | |
- apiGroups: [""] | |
resources: ["nodes/stats", "configmaps", "events"] | |
verbs: ["create"] | |
- apiGroups: [""] | |
resources: ["configmaps"] | |
resourceNames: ["cwagent-clusterleader"] | |
verbs: ["get","update"] | |
--- | |
kind: ClusterRoleBinding | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: cloudwatch-agent-role-binding | |
subjects: | |
- kind: ServiceAccount | |
name: cloudwatch-agent | |
namespace: amazon-cloudwatch | |
roleRef: | |
kind: ClusterRole | |
name: cloudwatch-agent-role | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
# create configmap for cwagent config | |
apiVersion: v1 | |
data: | |
# Configuration is in Json format. No matter what configure change you make, | |
# please keep the Json blob valid. | |
cwagentconfig.json: | | |
{ | |
"agent": { | |
"region": "ap-northeast-2" | |
}, | |
"logs": { | |
"metrics_collected": { | |
"kubernetes": { | |
"cluster_name": "Tony-Test-Light", | |
"metrics_collection_interval": 60 | |
} | |
}, | |
"force_flush_interval": 5 | |
} | |
} | |
kind: ConfigMap | |
metadata: | |
name: cwagentconfig | |
namespace: amazon-cloudwatch | |
--- | |
# deploy cwagent as daemonset | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: cloudwatch-agent | |
namespace: amazon-cloudwatch | |
spec: | |
selector: | |
matchLabels: | |
name: cloudwatch-agent | |
template: | |
metadata: | |
labels: | |
name: cloudwatch-agent | |
spec: | |
containers: | |
- name: cloudwatch-agent | |
image: amazon/cloudwatch-agent:1.247354.0b251981 | |
#ports: | |
# - containerPort: 8125 | |
# hostPort: 8125 | |
# protocol: UDP | |
resources: | |
limits: | |
cpu: 200m | |
memory: 200Mi | |
requests: | |
cpu: 200m | |
memory: 200Mi | |
# Please don't change below envs | |
env: | |
- name: HOST_IP | |
valueFrom: | |
fieldRef: | |
fieldPath: status.hostIP | |
- name: HOST_NAME | |
valueFrom: | |
fieldRef: | |
fieldPath: spec.nodeName | |
- name: K8S_NAMESPACE | |
valueFrom: | |
fieldRef: | |
fieldPath: metadata.namespace | |
- name: CI_VERSION | |
value: "k8s/1.3.11" | |
# Please don't change the mountPath | |
volumeMounts: | |
- name: cwagentconfig | |
mountPath: /etc/cwagentconfig | |
- name: rootfs | |
mountPath: /rootfs | |
readOnly: true | |
- name: dockersock | |
mountPath: /var/run/docker.sock | |
readOnly: true | |
- name: varlibdocker | |
mountPath: /var/lib/docker | |
readOnly: true | |
- name: containerdsock | |
mountPath: /run/containerd/containerd.sock | |
readOnly: true | |
- name: sys | |
mountPath: /sys | |
readOnly: true | |
- name: devdisk | |
mountPath: /dev/disk | |
readOnly: true | |
volumes: | |
- name: cwagentconfig | |
configMap: | |
name: cwagentconfig | |
- name: rootfs | |
hostPath: | |
path: / | |
- name: dockersock | |
hostPath: | |
path: /var/run/docker.sock | |
- name: varlibdocker | |
hostPath: | |
path: /var/lib/docker | |
- name: containerdsock | |
hostPath: | |
path: /run/containerd/containerd.sock | |
- name: sys | |
hostPath: | |
path: /sys | |
- name: devdisk | |
hostPath: | |
path: /dev/disk/ | |
terminationGracePeriodSeconds: 60 | |
serviceAccountName: cloudwatch-agent | |
--- | |
# create configmap for cluster name and aws region for CloudWatch Logs | |
# need to replace the placeholders Tony-Test-Light and ap-northeast-2 | |
# and need to replace "On" and "2020" | |
# and need to replace "Off" and "On" | |
apiVersion: v1 | |
data: | |
cluster.name: Tony-Test-Light | |
logs.region: ap-northeast-2 | |
http.server: "On" | |
http.port: "2020" | |
read.head: "Off" | |
read.tail: "On" | |
kind: ConfigMap | |
metadata: | |
name: fluent-bit-cluster-info | |
namespace: amazon-cloudwatch | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: fluent-bit | |
namespace: amazon-cloudwatch | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRole | |
metadata: | |
name: fluent-bit-role | |
rules: | |
- nonResourceURLs: | |
- /metrics | |
verbs: | |
- get | |
- apiGroups: [""] | |
resources: | |
- namespaces | |
- pods | |
- pods/logs | |
- nodes | |
- nodes/proxy | |
verbs: ["get", "list", "watch"] | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: fluent-bit-role-binding | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: ClusterRole | |
name: fluent-bit-role | |
subjects: | |
- kind: ServiceAccount | |
name: fluent-bit | |
namespace: amazon-cloudwatch | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: fluent-bit-config | |
namespace: amazon-cloudwatch | |
labels: | |
k8s-app: fluent-bit | |
data: | |
fluent-bit.conf: | | |
[SERVICE] | |
Flush 5 | |
Log_Level info | |
Daemon off | |
Parsers_File parsers.conf | |
HTTP_Server ${HTTP_SERVER} | |
HTTP_Listen 0.0.0.0 | |
HTTP_Port ${HTTP_PORT} | |
storage.path /var/fluent-bit/state/flb-storage/ | |
storage.sync normal | |
storage.checksum off | |
storage.backlog.mem_limit 5M | |
@INCLUDE application-log.conf | |
@INCLUDE dataplane-log.conf | |
@INCLUDE host-log.conf | |
application-log.conf: | | |
[INPUT] | |
Name tail | |
Tag application.* | |
Exclude_Path /var/log/containers/cloudwatch-agent*, /var/log/containers/fluent-bit*, /var/log/containers/aws-node*, /var/log/containers/kube-proxy* | |
Path /var/log/containers/*.log | |
Docker_Mode On | |
Docker_Mode_Flush 5 | |
Docker_Mode_Parser container_firstline | |
Parser docker | |
DB /var/fluent-bit/state/flb_container.db | |
Mem_Buf_Limit 50MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Rotate_Wait 30 | |
storage.type filesystem | |
Read_from_Head ${READ_FROM_HEAD} | |
[INPUT] | |
Name tail | |
Tag application.* | |
Path /var/log/containers/fluent-bit* | |
Parser docker | |
DB /var/fluent-bit/state/flb_log.db | |
Mem_Buf_Limit 5MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Read_from_Head ${READ_FROM_HEAD} | |
[INPUT] | |
Name tail | |
Tag application.* | |
Path /var/log/containers/cloudwatch-agent* | |
Docker_Mode On | |
Docker_Mode_Flush 5 | |
Docker_Mode_Parser cwagent_firstline | |
Parser docker | |
DB /var/fluent-bit/state/flb_cwagent.db | |
Mem_Buf_Limit 5MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Read_from_Head ${READ_FROM_HEAD} | |
[FILTER] | |
Name kubernetes | |
Match application.* | |
Kube_URL https://kubernetes.default.svc:443 | |
Kube_Tag_Prefix application.var.log.containers. | |
Merge_Log On | |
Merge_Log_Key log_processed | |
K8S-Logging.Parser On | |
K8S-Logging.Exclude Off | |
Labels Off | |
Annotations Off | |
Use_Kubelet On | |
Kubelet_Port 10250 | |
Buffer_Size 0 | |
[OUTPUT] | |
Name cloudwatch_logs | |
Match application.* | |
region ${AWS_REGION} | |
log_group_name /aws/containerinsights/${CLUSTER_NAME}/application | |
log_stream_prefix ${HOST_NAME}- | |
auto_create_group true | |
extra_user_agent container-insights | |
dataplane-log.conf: | | |
[INPUT] | |
Name systemd | |
Tag dataplane.systemd.* | |
Systemd_Filter _SYSTEMD_UNIT=docker.service | |
Systemd_Filter _SYSTEMD_UNIT=kubelet.service | |
DB /var/fluent-bit/state/systemd.db | |
Path /var/log/journal | |
Read_From_Tail ${READ_FROM_TAIL} | |
[INPUT] | |
Name tail | |
Tag dataplane.tail.* | |
Path /var/log/containers/aws-node*, /var/log/containers/kube-proxy* | |
Docker_Mode On | |
Docker_Mode_Flush 5 | |
Docker_Mode_Parser container_firstline | |
Parser docker | |
DB /var/fluent-bit/state/flb_dataplane_tail.db | |
Mem_Buf_Limit 50MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Rotate_Wait 30 | |
storage.type filesystem | |
Read_from_Head ${READ_FROM_HEAD} | |
[FILTER] | |
Name modify | |
Match dataplane.systemd.* | |
Rename _HOSTNAME hostname | |
Rename _SYSTEMD_UNIT systemd_unit | |
Rename MESSAGE message | |
Remove_regex ^((?!hostname|systemd_unit|message).)*$ | |
[FILTER] | |
Name aws | |
Match dataplane.* | |
imds_version v1 | |
[OUTPUT] | |
Name cloudwatch_logs | |
Match dataplane.* | |
region ${AWS_REGION} | |
log_group_name /aws/containerinsights/${CLUSTER_NAME}/dataplane | |
log_stream_prefix ${HOST_NAME}- | |
auto_create_group true | |
extra_user_agent container-insights | |
host-log.conf: | | |
[INPUT] | |
Name tail | |
Tag host.dmesg | |
Path /var/log/dmesg | |
Parser syslog | |
DB /var/fluent-bit/state/flb_dmesg.db | |
Mem_Buf_Limit 5MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Read_from_Head ${READ_FROM_HEAD} | |
[INPUT] | |
Name tail | |
Tag host.messages | |
Path /var/log/messages | |
Parser syslog | |
DB /var/fluent-bit/state/flb_messages.db | |
Mem_Buf_Limit 5MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Read_from_Head ${READ_FROM_HEAD} | |
[INPUT] | |
Name tail | |
Tag host.secure | |
Path /var/log/secure | |
Parser syslog | |
DB /var/fluent-bit/state/flb_secure.db | |
Mem_Buf_Limit 5MB | |
Skip_Long_Lines On | |
Refresh_Interval 10 | |
Read_from_Head ${READ_FROM_HEAD} | |
[FILTER] | |
Name aws | |
Match host.* | |
imds_version v1 | |
[OUTPUT] | |
Name cloudwatch_logs | |
Match host.* | |
region ${AWS_REGION} | |
log_group_name /aws/containerinsights/${CLUSTER_NAME}/host | |
log_stream_prefix ${HOST_NAME}. | |
auto_create_group true | |
extra_user_agent container-insights | |
parsers.conf: | | |
[PARSER] | |
Name docker | |
Format json | |
Time_Key time | |
Time_Format %Y-%m-%dT%H:%M:%S.%LZ | |
[PARSER] | |
Name syslog | |
Format regex | |
Regex ^(?<time>[^ ]* {1,2}[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?(?:[^\:]*\:)? *(?<message>.*)$ | |
Time_Key time | |
Time_Format %b %d %H:%M:%S | |
[PARSER] | |
Name container_firstline | |
Format regex | |
Regex (?<log>(?<="log":")\S(?!\.).*?)(?<!\\)".*(?<stream>(?<="stream":").*?)".*(?<time>\d{4}-\d{1,2}-\d{1,2}T\d{2}:\d{2}:\d{2}\.\w*).*(?=}) | |
Time_Key time | |
Time_Format %Y-%m-%dT%H:%M:%S.%LZ | |
[PARSER] | |
Name cwagent_firstline | |
Format regex | |
Regex (?<log>(?<="log":")\d{4}[\/-]\d{1,2}[\/-]\d{1,2}[ T]\d{2}:\d{2}:\d{2}(?!\.).*?)(?<!\\)".*(?<stream>(?<="stream":").*?)".*(?<time>\d{4}-\d{1,2}-\d{1,2}T\d{2}:\d{2}:\d{2}\.\w*).*(?=}) | |
Time_Key time | |
Time_Format %Y-%m-%dT%H:%M:%S.%LZ | |
--- | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: fluent-bit | |
namespace: amazon-cloudwatch | |
labels: | |
k8s-app: fluent-bit | |
version: v1 | |
kubernetes.io/cluster-service: "true" | |
spec: | |
selector: | |
matchLabels: | |
k8s-app: fluent-bit | |
template: | |
metadata: | |
labels: | |
k8s-app: fluent-bit | |
version: v1 | |
kubernetes.io/cluster-service: "true" | |
spec: | |
containers: | |
- name: fluent-bit | |
image: public.ecr.aws/aws-observability/aws-for-fluent-bit:stable | |
imagePullPolicy: Always | |
env: | |
- name: AWS_REGION | |
valueFrom: | |
configMapKeyRef: | |
name: fluent-bit-cluster-info | |
key: logs.region | |
- name: CLUSTER_NAME | |
valueFrom: | |
configMapKeyRef: | |
name: fluent-bit-cluster-info | |
key: cluster.name | |
- name: HTTP_SERVER | |
valueFrom: | |
configMapKeyRef: | |
name: fluent-bit-cluster-info | |
key: http.server | |
- name: HTTP_PORT | |
valueFrom: | |
configMapKeyRef: | |
name: fluent-bit-cluster-info | |
key: http.port | |
- name: READ_FROM_HEAD | |
valueFrom: | |
configMapKeyRef: | |
name: fluent-bit-cluster-info | |
key: read.head | |
- name: READ_FROM_TAIL | |
valueFrom: | |
configMapKeyRef: | |
name: fluent-bit-cluster-info | |
key: read.tail | |
- name: HOST_NAME | |
valueFrom: | |
fieldRef: | |
fieldPath: spec.nodeName | |
- name: HOSTNAME | |
valueFrom: | |
fieldRef: | |
apiVersion: v1 | |
fieldPath: metadata.name | |
- name: CI_VERSION | |
value: "k8s/1.3.11" | |
resources: | |
limits: | |
memory: 200Mi | |
requests: | |
cpu: 500m | |
memory: 100Mi | |
volumeMounts: | |
# Please don't change below read-only permissions | |
- name: fluentbitstate | |
mountPath: /var/fluent-bit/state | |
- name: varlog | |
mountPath: /var/log | |
readOnly: true | |
- name: varlibdockercontainers | |
mountPath: /var/lib/docker/containers | |
readOnly: true | |
- name: fluent-bit-config | |
mountPath: /fluent-bit/etc/ | |
- name: runlogjournal | |
mountPath: /run/log/journal | |
readOnly: true | |
- name: dmesg | |
mountPath: /var/log/dmesg | |
readOnly: true | |
terminationGracePeriodSeconds: 10 | |
hostNetwork: true | |
dnsPolicy: ClusterFirstWithHostNet | |
volumes: | |
- name: fluentbitstate | |
hostPath: | |
path: /var/fluent-bit/state | |
- name: varlog | |
hostPath: | |
path: /var/log | |
- name: varlibdockercontainers | |
hostPath: | |
path: /var/lib/docker/containers | |
- name: fluent-bit-config | |
configMap: | |
name: fluent-bit-config | |
- name: runlogjournal | |
hostPath: | |
path: /run/log/journal | |
- name: dmesg | |
hostPath: | |
path: /var/log/dmesg | |
serviceAccountName: fluent-bit | |
tolerations: | |
- key: node-role.kubernetes.io/master | |
operator: Exists | |
effect: NoSchedule | |
- operator: "Exists" | |
effect: "NoExecute" | |
- operator: "Exists" | |
effect: "NoSchedule" |
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
# create amazon-cloudwatch namespace | |
apiVersion: v1 | |
kind: Namespace | |
metadata: | |
name: amazon-cloudwatch | |
labels: | |
name: amazon-cloudwatch | |
--- | |
# create cwagent service account and role binding | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: cloudwatch-agent | |
namespace: amazon-cloudwatch | |
--- | |
kind: ClusterRole | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: cloudwatch-agent-role | |
rules: | |
- apiGroups: [""] | |
resources: ["pods", "nodes", "endpoints"] | |
verbs: ["list", "watch"] | |
- apiGroups: ["apps"] | |
resources: ["replicasets", "daemonsets", "deployments"] | |
verbs: ["list", "watch"] | |
- apiGroups: ["batch"] | |
resources: ["jobs"] | |
verbs: ["list", "watch"] | |
- apiGroups: [""] | |
resources: ["nodes/proxy"] | |
verbs: ["get"] | |
- apiGroups: [""] | |
resources: ["nodes/stats", "configmaps", "events"] | |
verbs: ["create"] | |
- apiGroups: [""] | |
resources: ["configmaps"] | |
resourceNames: ["cwagent-clusterleader"] | |
verbs: ["get","update"] | |
- nonResourceURLs: ["/metrics"] | |
verbs: ["get", "list", "watch"] | |
--- | |
kind: ClusterRoleBinding | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: cloudwatch-agent-role-binding | |
subjects: | |
- kind: ServiceAccount | |
name: cloudwatch-agent | |
namespace: amazon-cloudwatch | |
roleRef: | |
kind: ClusterRole | |
name: cloudwatch-agent-role | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
# create configmap for cwagent config | |
apiVersion: v1 | |
data: | |
# Configuration is in Json format. No matter what configure change you make, | |
# please keep the Json blob valid. | |
cwagentconfig.json: | | |
{ | |
"agent": { | |
"region": "{{region_name}}" | |
}, | |
"logs": { | |
"metrics_collected": { | |
"kubernetes": { | |
"cluster_name": "{{cluster_name}}", | |
"metrics_collection_interval": 60 | |
} | |
}, | |
"force_flush_interval": 5 | |
} | |
} | |
kind: ConfigMap | |
metadata: | |
name: cwagentconfig | |
namespace: amazon-cloudwatch | |
--- | |
# deploy cwagent as daemonset | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: cloudwatch-agent | |
namespace: amazon-cloudwatch | |
spec: | |
selector: | |
matchLabels: | |
name: cloudwatch-agent | |
template: | |
metadata: | |
labels: | |
name: cloudwatch-agent | |
spec: | |
containers: | |
- name: cloudwatch-agent | |
image: public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300028.1b210 | |
#ports: | |
# - containerPort: 8125 | |
# hostPort: 8125 | |
# protocol: UDP | |
resources: | |
limits: | |
cpu: 400m | |
memory: 400Mi | |
requests: | |
cpu: 400m | |
memory: 400Mi | |
# Please don't change below envs | |
env: | |
- name: HOST_IP | |
valueFrom: | |
fieldRef: | |
fieldPath: status.hostIP | |
- name: HOST_NAME | |
valueFrom: | |
fieldRef: | |
fieldPath: spec.nodeName | |
- name: K8S_NAMESPACE | |
valueFrom: | |
fieldRef: | |
fieldPath: metadata.namespace | |
- name: CI_VERSION | |
value: "k8s/1.3.17" | |
# Please don't change the mountPath | |
volumeMounts: | |
- name: cwagentconfig | |
mountPath: /etc/cwagentconfig | |
- name: rootfs | |
mountPath: /rootfs | |
readOnly: true | |
- name: dockersock | |
mountPath: /var/run/docker.sock | |
readOnly: true | |
- name: varlibdocker | |
mountPath: /var/lib/docker | |
readOnly: true | |
- name: containerdsock | |
mountPath: /run/containerd/containerd.sock | |
readOnly: true | |
- name: sys | |
mountPath: /sys | |
readOnly: true | |
- name: devdisk | |
mountPath: /dev/disk | |
readOnly: true | |
nodeSelector: | |
kubernetes.io/os: linux | |
volumes: | |
- name: cwagentconfig | |
configMap: | |
name: cwagentconfig | |
- name: rootfs | |
hostPath: | |
path: / | |
- name: dockersock | |
hostPath: | |
path: /var/run/docker.sock | |
- name: varlibdocker | |
hostPath: | |
path: /var/lib/docker | |
- name: containerdsock | |
hostPath: | |
path: /run/containerd/containerd.sock | |
- name: sys | |
hostPath: | |
path: /sys | |
- name: devdisk | |
hostPath: | |
path: /dev/disk/ | |
terminationGracePeriodSeconds: 60 | |
serviceAccountName: cloudwatch-agent | |
--- | |
# create configmap for cluster name and aws region for CloudWatch Logs | |
# need to replace the placeholders {{cluster_name}} and {{region_name}} | |
apiVersion: v1 | |
data: | |
cluster.name: {{cluster_name}} | |
logs.region: {{region_name}} | |
kind: ConfigMap | |
metadata: | |
name: cluster-info | |
namespace: amazon-cloudwatch | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: fluentd | |
namespace: amazon-cloudwatch | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRole | |
metadata: | |
name: fluentd-role | |
rules: | |
- apiGroups: [""] | |
resources: | |
- namespaces | |
- pods | |
- pods/logs | |
verbs: ["get", "list", "watch"] | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: fluentd-role-binding | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: ClusterRole | |
name: fluentd-role | |
subjects: | |
- kind: ServiceAccount | |
name: fluentd | |
namespace: amazon-cloudwatch | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: fluentd-config | |
namespace: amazon-cloudwatch | |
labels: | |
k8s-app: fluentd-cloudwatch | |
data: | |
kubernetes.conf: | | |
kubernetes.conf | |
fluent.conf: | | |
@include containers.conf | |
@include systemd.conf | |
@include host.conf | |
<match fluent.**> | |
@type null | |
</match> | |
containers.conf: | | |
<source> | |
@type tail | |
@id in_tail_container_logs | |
@label @containers | |
path /var/log/containers/*.log | |
exclude_path ["/var/log/containers/cloudwatch-agent*", "/var/log/containers/fluentd*"] | |
pos_file /var/log/fluentd-containers.log.pos | |
tag * | |
read_from_head true | |
<parse> | |
@type "#{ENV['FLUENT_CONTAINER_TAIL_PARSER_TYPE'] || 'json'}" | |
time_format %Y-%m-%dT%H:%M:%S.%N%:z | |
</parse> | |
</source> | |
<source> | |
@type tail | |
@id in_tail_cwagent_logs | |
@label @cwagentlogs | |
path /var/log/containers/cloudwatch-agent* | |
pos_file /var/log/cloudwatch-agent.log.pos | |
tag * | |
read_from_head true | |
<parse> | |
@type json | |
time_format %Y-%m-%dT%H:%M:%S.%NZ | |
</parse> | |
</source> | |
<source> | |
@type tail | |
@id in_tail_fluentd_logs | |
@label @fluentdlogs | |
path /var/log/containers/fluentd* | |
pos_file /var/log/fluentd.log.pos | |
tag * | |
read_from_head true | |
<parse> | |
@type json | |
time_format %Y-%m-%dT%H:%M:%S.%NZ | |
</parse> | |
</source> | |
<label @fluentdlogs> | |
<filter **> | |
@type kubernetes_metadata | |
@id filter_kube_metadata_fluentd | |
watch false | |
</filter> | |
<filter **> | |
@type record_transformer | |
@id filter_fluentd_stream_transformer | |
<record> | |
stream_name ${tag_parts[3]} | |
</record> | |
</filter> | |
<match **> | |
@type relabel | |
@label @NORMAL | |
</match> | |
</label> | |
<label @containers> | |
<filter **> | |
@type kubernetes_metadata | |
@id filter_kube_metadata | |
watch false | |
</filter> | |
<filter **> | |
@type record_transformer | |
@id filter_containers_stream_transformer | |
<record> | |
stream_name ${tag_parts[3]} | |
</record> | |
</filter> | |
<filter **> | |
@type concat | |
key log | |
multiline_start_regexp /^\S/ | |
separator "" | |
flush_interval 5 | |
timeout_label @NORMAL | |
</filter> | |
<match **> | |
@type relabel | |
@label @NORMAL | |
</match> | |
</label> | |
<label @cwagentlogs> | |
<filter **> | |
@type kubernetes_metadata | |
@id filter_kube_metadata_cwagent | |
watch false | |
</filter> | |
<filter **> | |
@type record_transformer | |
@id filter_cwagent_stream_transformer | |
<record> | |
stream_name ${tag_parts[3]} | |
</record> | |
</filter> | |
<filter **> | |
@type concat | |
key log | |
multiline_start_regexp /^\d{4}[-/]\d{1,2}[-/]\d{1,2}/ | |
separator "" | |
flush_interval 5 | |
timeout_label @NORMAL | |
</filter> | |
<match **> | |
@type relabel | |
@label @NORMAL | |
</match> | |
</label> | |
<label @NORMAL> | |
<match **> | |
@type cloudwatch_logs | |
@id out_cloudwatch_logs_containers | |
region "#{ENV.fetch('AWS_REGION')}" | |
log_group_name "/aws/containerinsights/#{ENV.fetch('CLUSTER_NAME')}/application" | |
log_stream_name_key stream_name | |
remove_log_stream_name_key true | |
auto_create_stream true | |
<buffer> | |
flush_interval 5 | |
chunk_limit_size 2m | |
queued_chunks_limit_size 32 | |
retry_forever true | |
</buffer> | |
</match> | |
</label> | |
systemd.conf: | | |
<source> | |
@type systemd | |
@id in_systemd_kubelet | |
@label @systemd | |
filters [{ "_SYSTEMD_UNIT": "kubelet.service" }] | |
<entry> | |
field_map {"MESSAGE": "message", "_HOSTNAME": "hostname", "_SYSTEMD_UNIT": "systemd_unit"} | |
field_map_strict true | |
</entry> | |
path /var/log/journal | |
<storage> | |
@type local | |
persistent true | |
path /var/log/fluentd-journald-kubelet-pos.json | |
</storage> | |
read_from_head true | |
tag kubelet.service | |
</source> | |
<source> | |
@type systemd | |
@id in_systemd_kubeproxy | |
@label @systemd | |
filters [{ "_SYSTEMD_UNIT": "kubeproxy.service" }] | |
<entry> | |
field_map {"MESSAGE": "message", "_HOSTNAME": "hostname", "_SYSTEMD_UNIT": "systemd_unit"} | |
field_map_strict true | |
</entry> | |
path /var/log/journal | |
<storage> | |
@type local | |
persistent true | |
path /var/log/fluentd-journald-kubeproxy-pos.json | |
</storage> | |
read_from_head true | |
tag kubeproxy.service | |
</source> | |
<source> | |
@type systemd | |
@id in_systemd_docker | |
@label @systemd | |
filters [{ "_SYSTEMD_UNIT": "docker.service" }] | |
<entry> | |
field_map {"MESSAGE": "message", "_HOSTNAME": "hostname", "_SYSTEMD_UNIT": "systemd_unit"} | |
field_map_strict true | |
</entry> | |
path /var/log/journal | |
<storage> | |
@type local | |
persistent true | |
path /var/log/fluentd-journald-docker-pos.json | |
</storage> | |
read_from_head true | |
tag docker.service | |
</source> | |
<label @systemd> | |
<filter **> | |
@type kubernetes_metadata | |
@id filter_kube_metadata_systemd | |
watch false | |
</filter> | |
<filter **> | |
@type record_transformer | |
@id filter_systemd_stream_transformer | |
<record> | |
stream_name ${tag}-${record["hostname"]} | |
</record> | |
</filter> | |
<match **> | |
@type cloudwatch_logs | |
@id out_cloudwatch_logs_systemd | |
region "#{ENV.fetch('AWS_REGION')}" | |
log_group_name "/aws/containerinsights/#{ENV.fetch('CLUSTER_NAME')}/dataplane" | |
log_stream_name_key stream_name | |
auto_create_stream true | |
remove_log_stream_name_key true | |
<buffer> | |
flush_interval 5 | |
chunk_limit_size 2m | |
queued_chunks_limit_size 32 | |
retry_forever true | |
</buffer> | |
</match> | |
</label> | |
host.conf: | | |
<source> | |
@type tail | |
@id in_tail_dmesg | |
@label @hostlogs | |
path /var/log/dmesg | |
pos_file /var/log/dmesg.log.pos | |
tag host.dmesg | |
read_from_head true | |
<parse> | |
@type syslog | |
</parse> | |
</source> | |
<source> | |
@type tail | |
@id in_tail_secure | |
@label @hostlogs | |
path /var/log/secure | |
pos_file /var/log/secure.log.pos | |
tag host.secure | |
read_from_head true | |
<parse> | |
@type syslog | |
</parse> | |
</source> | |
<source> | |
@type tail | |
@id in_tail_messages | |
@label @hostlogs | |
path /var/log/messages | |
pos_file /var/log/messages.log.pos | |
tag host.messages | |
read_from_head true | |
<parse> | |
@type syslog | |
</parse> | |
</source> | |
<label @hostlogs> | |
<filter **> | |
@type kubernetes_metadata | |
@id filter_kube_metadata_host | |
watch false | |
</filter> | |
<filter **> | |
@type record_transformer | |
@id filter_containers_stream_transformer_host | |
<record> | |
stream_name ${tag}-${record["host"]} | |
</record> | |
</filter> | |
<match host.**> | |
@type cloudwatch_logs | |
@id out_cloudwatch_logs_host_logs | |
region "#{ENV.fetch('AWS_REGION')}" | |
log_group_name "/aws/containerinsights/#{ENV.fetch('CLUSTER_NAME')}/host" | |
log_stream_name_key stream_name | |
remove_log_stream_name_key true | |
auto_create_stream true | |
<buffer> | |
flush_interval 5 | |
chunk_limit_size 2m | |
queued_chunks_limit_size 32 | |
retry_forever true | |
</buffer> | |
</match> | |
</label> | |
--- | |
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: fluentd-cloudwatch | |
namespace: amazon-cloudwatch | |
spec: | |
selector: | |
matchLabels: | |
k8s-app: fluentd-cloudwatch | |
template: | |
metadata: | |
labels: | |
k8s-app: fluentd-cloudwatch | |
annotations: | |
configHash: 8915de4cf9c3551a8dc74c0137a3e83569d28c71044b0359c2578d2e0461825 | |
spec: | |
serviceAccountName: fluentd | |
terminationGracePeriodSeconds: 30 | |
# Because the image's entrypoint requires to write on /fluentd/etc but we mount configmap there which is read-only, | |
# this initContainers workaround or other is needed. | |
# See https://github.com/fluent/fluentd-kubernetes-daemonset/issues/90 | |
initContainers: | |
- name: copy-fluentd-config | |
image: busybox | |
command: ['sh', '-c', 'cp /config-volume/..data/* /fluentd/etc'] | |
volumeMounts: | |
- name: config-volume | |
mountPath: /config-volume | |
- name: fluentdconf | |
mountPath: /fluentd/etc | |
- name: update-log-driver | |
image: busybox | |
command: ['sh','-c',''] | |
containers: | |
- name: fluentd-cloudwatch | |
image: fluent/fluentd-kubernetes-daemonset:v1.10.3-debian-cloudwatch-1.0 | |
env: | |
- name: AWS_REGION | |
valueFrom: | |
configMapKeyRef: | |
name: cluster-info | |
key: logs.region | |
- name: CLUSTER_NAME | |
valueFrom: | |
configMapKeyRef: | |
name: cluster-info | |
key: cluster.name | |
- name: CI_VERSION | |
value: "k8s/1.3.17" | |
- name: FLUENT_CONTAINER_TAIL_PARSER_TYPE | |
value: /^(?<time>.+) (?<stream>stdout|stderr) (?<logtag>[FP]) (?<log>.*)$/ | |
resources: | |
limits: | |
memory: 400Mi | |
requests: | |
cpu: 100m | |
memory: 200Mi | |
volumeMounts: | |
- name: config-volume | |
mountPath: /config-volume | |
- name: fluentdconf | |
mountPath: /fluentd/etc | |
- name: fluentd-config | |
mountPath: /fluentd/etc/kubernetes.conf | |
subPath: kubernetes.conf | |
- name: varlog | |
mountPath: /var/log | |
- name: varlibdockercontainers | |
mountPath: /var/lib/docker/containers | |
readOnly: true | |
- name: runlogjournal | |
mountPath: /run/log/journal | |
readOnly: true | |
- name: dmesg | |
mountPath: /var/log/dmesg | |
readOnly: true | |
volumes: | |
- name: config-volume | |
configMap: | |
name: fluentd-config | |
- name: fluentdconf | |
emptyDir: {} | |
- name: fluentd-config | |
configMap: | |
name: fluentd-config | |
items: | |
- key: kubernetes.conf | |
path: kubernetes.conf | |
- name: varlog | |
hostPath: | |
path: /var/log | |
- name: varlibdockercontainers | |
hostPath: | |
path: /var/lib/docker/containers | |
- name: runlogjournal | |
hostPath: | |
path: /run/log/journal | |
- name: dmesg | |
hostPath: | |
path: /var/log/dmesg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment