通過自定義方案采集應用日志
部署在容器計算服務 ACS(Container Compute Service)的應用除了使用阿里云日志服務(SLS)采集日志之外,還可以構(gòu)建自己的日志采集系統(tǒng),比如:EFK(ElasticSearch,F(xiàn)ileBeat,Kibana)。由于ACS不支持部署DaemonSet組件,因此日志采集Agent FileBeat需要使用Sidecar的形態(tài)進行日志采集,本文主要介紹如何在ACS上部署自定義的日志采集Agent。
前提條件
已創(chuàng)建ACS集群。具體操作,請參見創(chuàng)建ACS集群。
背景信息
常見的日志采集方案都會有一個Agent用于采集業(yè)務日志,即在每個Pod實例中,除業(yè)務容器外,運行一個Sidecar容器作為日志Agent(例如:FileBeat),用于采集業(yè)務容器產(chǎn)生的日志。
Sidecar模式日志采集Agent必須和業(yè)務容器共享日志目錄,業(yè)務容器將日志寫入到共享目錄中,Logtail通過監(jiān)控共享目錄中日志文件的變化并采集日志。
采集的日志可以分為以下兩種:
標準輸出
采集標準輸出依賴于Medium為Stdout的EmptyDir卷。創(chuàng)建Pod時可以將該卷掛載到Sidecar容器上,Sidecar可以直接以文件的方式訪問ACS基礎組件收集的標準輸出日志。
說明每個Pod最多可以聲明1個Medium為Stdout的EmptyDir卷,并需要掛載到至少1個容器內(nèi)。
采集標準輸出會帶來一定的性能開銷和存儲成本。
標準輸出日志已配置自動輪轉(zhuǎn),具體規(guī)則參考日志輪轉(zhuǎn)。其中,每個日志文件到達10MiB之后將啟動輪轉(zhuǎn),并且每個容器允許的最大文件數(shù)為5。
文本文件
采集文本文件可以通過Pod內(nèi)共享的volume實現(xiàn)。Pod內(nèi)同一個volume可以掛載到多個容器,Sidecar可以直接收集業(yè)務容器輸出到對應volume內(nèi)的文本文件。
功能介紹
容器啟動和退出順序和Job類Pod
Sidecar容器常需要如下兩個訴求:
Sidecar容器需要在業(yè)務容器前啟動,在業(yè)務容器后推出。
對于Job類Pod而言,Sidecar容器需要在業(yè)務容器退出后主動退出。
在ACS場景下,你可以在Sidecar容器上面設置環(huán)境變量__IS_SIDECAR__="true"
來實現(xiàn)上述訴求。更多信息,請參見配置Sidecar容器啟停順序。
Sidecar模式采集容器文件日志
Sidecar容器如果是采集業(yè)務容器的文件日志,可以通過共享volume的方式。更多信息,請參見使用Sidecar模式采集業(yè)務容器文件日志。
Sidecar模式采集容器標準輸出
在ACS場景下,可以通過配置volumes.emptyDir.medium=Stdout
來實現(xiàn)采集容器標準輸出的效果。詳細配置,請參見場景一。
場景一:采集應用文件日志和標準輸出
使用以下內(nèi)容,創(chuàng)建一個包含F(xiàn)ilebeat Sidecar容器的Deployment。
您可以用相同的方式配置StatefulSet。
apiVersion: v1 kind: ConfigMap metadata: name: filebeat-config data: filebeat.yml: | filebeat.inputs: - type: log paths: - /var/log/* - /stdout/* output.elasticsearch: host: '${NODE_NAME}' hosts: '["https://${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}"]' username: '${ELASTICSEARCH_USERNAME}' password: '${ELASTICSEARCH_PASSWORD}' protocol: https ssl.certificate_authorities: [ "/usr/share/filebeat/certs/ca.crt" ] --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - args: - -e - -E - http.enabled=true env: - name: POD_NAMESPACE valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.namespace - name: NODE_NAME valueFrom: fieldRef: apiVersion: v1 fieldPath: spec.nodeName - name: ELASTICSEARCH_USERNAME valueFrom: secretKeyRef: key: username name: elasticsearch-master-credentials - name: ELASTICSEARCH_PASSWORD valueFrom: secretKeyRef: key: password name: elasticsearch-master-credentials - name: __IS_SIDECAR__ value: "true" image: mirrors-ssl.aliyuncs.com/docker.elastic.co/beats/filebeat:8.5.1 imagePullPolicy: Always name: filebeat resources: limits: cpu: 250m ephemeral-storage: 30Gi memory: 512Mi requests: cpu: 250m ephemeral-storage: 30Gi memory: 512Mi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /var/log name: varlog readOnly: true - mountPath: /stdout name: stdout-log readOnly: true - mountPath: /usr/share/filebeat/certs/ name: elasticsearch-master-certs - mountPath: /usr/share/filebeat/filebeat.yml name: filebeat-config readOnly: true subPath: filebeat.yml - image: mirrors-ssl.aliyuncs.com/nginx:latest name: nginx volumeMounts: - mountPath: /var/log/nginx name: varlog volumes: ## 共享volume,采集文件日志 - emptyDir: {} name: varlog ## 采集標準輸出 - emptyDir: medium: Stdout name: stdout-log - name: elasticsearch-master-certs secret: secretName: elasticsearch-master-certs - configMap: name: filebeat-config name: filebeat-config # 下面的配置只是單純?yōu)榱吮疚臋n的示例 # 在真實環(huán)境中需要替換為,部署EFK的時候自動生成的配置 --- apiVersion: v1 data: ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJakNDQWdxZ0F3SUJBZ0lSQUl0SDZxR2YzRG9VNFBuVWRJOUdITlV3RFFZSktvWklodmNOQVFFTEJRQXcKR3pFWk1CY0dBMVVFQXhNUVpXeGhjM1JwWTNObFlYSmphQzFqWVRBZUZ3MHlOREV3TWprd056RTNNamxhRncweQpOVEV3TWprd056RTNNamxhTUJzeEdUQVhCZ05WQkFNVEVHVnNZWE4wYVdOelpXRnlZMmd0WTJFd2dnRWlNQTBHCkNTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFET1Zxc0svVXAvWTVNRVY5T3hzTUk2TTZMTFhYMGsKNFBGSjE0SklVNStUVnBRVVNhVmx3N0REeGtJaUQ3RDVHZ3I3Snh4WHV0cFNjVlo0QWN0UzNrNFJvV3lqdzg0cApoYW4wY3JZL2VaQmJlWjVFUUhCSXprU0ZhMWd4bkpUcVErSSsvR3lKSlNHNkQyR21UVHRqRXZ2R2pWL1loSDNHCk1DMnRadVNXN1hPYWZBKzFqWUNkVFpIZkNpeDdBZURVNU0zcVplNzR4MjhTeitDNkM4WUFCQ0ZSTnJsVGNFQW8KaGQ5WGNnellPUGdJY2VZSUJWb25DTDdzVWFPZGVKa1hrbmdBR2ZzWjB6RnJ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MGc2bzBCeFk1MXlmejlwbXZhOHRXCmc4Y3FMUUhEdFFZY3VYUkhNcE1ZY2RrQ2dZRUFrZHdxbys5OEo3cDR1Rkg1T2xCZWtSVFZxOXpsWVNlOGFFSi8KS3BKTVFpVUNsekVqY0NnZ2xaRjF5NGZhZFo5b0l5OVhZZ29FVkZGbzl3WW9MeWNFdXdMM1lKV3laMHJtL01pegpNOWNzWG8raVhDV29taVRFUmx2SUZxQUNiVUtIazcvdWFTeFI0S3RKNzhNN2x2TW5Ea1pCRVJkQ0lVTklsNEp4CkhleDhsVlVDZ1lCdlVMQUU3WkMyTkFnZUpYUmpRalFRd2laNU1jS09rTTBvVjlsYUlaR0xZUUVTOHVtYXA0THYKMVc5clN4UElxMTg3Q1haejBuOTdPN210aUpwYXhERDg1QVdZMEg5MGhFNitvZUltWmlPN3ZYbW5RTVRNZjNtWgp6dUcvNk84ckpsNWcyNnY4NTVBYjVUbC9ZQTNRcW1tOVdKdUt5eGw1bWxvMGkxNU14cWNia1E9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo= kind: Secret metadata: name: elasticsearch-master-certs type: kubernetes.io/tls --- apiVersion: v1 data: password: Z3BVMTFFZXZNWWFmMkVCUw== username: ZWxhc3RpYw== kind: Secret metadata: name: elasticsearch-master-credentials type: Opaque
執(zhí)行以下命令,獲取Pod信息。
kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE nginx-85776xxxxx-xxxxx 2/2 Running 0 13m
查看日志。
執(zhí)行以下命令,進入到filebeat容器。
kubectl exec -it deploy/nginx -c filebeat -- /bin/bash
在filebeat容器中查看應用日志。
cat /var/log/error.log
預期輸出:
2024/10/30 10:38:28 [notice] 1#1: using the "epoll" event method 2024/10/30 10:38:28 [notice] 1#1: nginx/1.21.5 2024/10/30 10:38:28 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 2024/10/30 10:38:28 [notice] 1#1: OS: Linux 5.10.134-17.0.2.lifsea8.x86_64 2024/10/30 10:38:28 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 2024/10/30 10:38:28 [notice] 1#1: start worker processes 2024/10/30 10:38:28 [notice] 1#1: start worker process 32
在filebeat容器中查看標準輸出。
cat /stdout/nginx/0.log
預期輸出:
2024-10-30T18:38:28.37305498+08:00 stdout F /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration 2024-10-30T18:38:28.373072927+08:00 stdout F /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ 2024-10-30T18:38:28.379999685+08:00 stdout F /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 2024-10-30T18:38:28.391562633+08:00 stdout F 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 2024-10-30T18:38:28.405538758+08:00 stdout F 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf 2024-10-30T18:38:28.405657957+08:00 stdout F /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh 2024-10-30T18:38:28.409014952+08:00 stdout F /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh 2024-10-30T18:38:28.410397615+08:00 stdout F /docker-entrypoint.sh: Configuration complete; ready for start up
場景二:采集任務型應用日志
使用以下內(nèi)容,部署基于busybox構(gòu)建打印標準輸出的任務。此任務執(zhí)行100s之后會自動退出。
以下兩種YAML分別展示了不同的Sidecar容器配置方式,部署后的任務是完全相同的。
K8s 1.28及以下版本
使用以下內(nèi)容部署任務busybox-stdout。
apiVersion: v1 kind: ConfigMap metadata: name: filebeat-config data: filebeat.yml: | filebeat.inputs: - type: log paths: - /stdout/* output.elasticsearch: host: '${NODE_NAME}' hosts: '["https://${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}"]' username: '${ELASTICSEARCH_USERNAME}' password: '${ELASTICSEARCH_PASSWORD}' protocol: https ssl.certificate_authorities: [ "/usr/share/filebeat/certs/ca.crt" ] --- apiVersion: batch/v1 kind: Job metadata: name: busybox-stdout spec: template: spec: containers: - args: - -e - -E - http.enabled=true env: - name: POD_NAMESPACE valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.namespace - name: NODE_NAME valueFrom: fieldRef: apiVersion: v1 fieldPath: spec.nodeName - name: ELASTICSEARCH_USERNAME valueFrom: secretKeyRef: key: username name: elasticsearch-master-credentials - name: ELASTICSEARCH_PASSWORD valueFrom: secretKeyRef: key: password name: elasticsearch-master-credentials - name: __IS_SIDECAR__ value: "true" image: mirrors-ssl.aliyuncs.com/docker.elastic.co/beats/filebeat:8.5.1 imagePullPolicy: Always name: filebeat resources: limits: cpu: 250m ephemeral-storage: 30Gi memory: 512Mi requests: cpu: 250m ephemeral-storage: 30Gi memory: 512Mi volumeMounts: - mountPath: /stdout name: stdout-log readOnly: true - mountPath: /usr/share/filebeat/certs/ name: elasticsearch-master-certs - mountPath: /usr/share/filebeat/filebeat.yml name: filebeat-config readOnly: true subPath: filebeat.yml - name: busybox image: mirrors-ssl.aliyuncs.com/busybox:latest command: [ "sh", "-c" ] args: - | for i in $(seq 1 100); do echo "Log message $i" sleep 1 done volumes: ## 采集標準輸出日志 - emptyDir: medium: Stdout name: stdout-log - name: elasticsearch-master-certs secret: secretName: elasticsearch-master-certs - configMap: name: filebeat-config name: filebeat-config restartPolicy: OnFailure # 下面的配置只是單純?yōu)榱吮疚臋n的示例 # 在真實環(huán)境中需要替換為,部署EFK的時候自動生成的配置 --- apiVersion: v1 data: ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJakNDQWdxZ0F3SUJBZ0lSQUl0SDZxR2YzRG9VNFBuVWRJOUdITlV3RFFZSktvWklodmNOQVFFTEJRQXcKR3pFWk1CY0dBMVVFQXhNUVpXeGhjM1JwWTNObFlYSmphQzFqWVRBZUZ3MHlOREV3TWprd056RTNNamxhRncweQpOVEV3TWprd056RTNNamxhTUJze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: name: elasticsearch-master-certs type: kubernetes.io/tls --- apiVersion: v1 data: password: Z3BVMTFFZXZNWWFmMkVCUw== username: ZWxhc3RpYw== kind: Secret metadata: name: elasticsearch-master-credentials type: Opaque
進入到filebeat容器,可以看到已經(jīng)共享了nginx容器的文件日志和標準輸出。
% kubectl exec -it busybox-stdout-4fwnx -c filebeat -- /bin/bash $ cat /stdout/busybox/0.log 2024-11-07T18:46:06.77002301+08:00 stdout F Log message 1 2024-11-07T18:46:07.77143368+08:00 stdout F Log message 2 2024-11-07T18:46:08.772840307+08:00 stdout F Log message 3 2024-11-07T18:46:09.774047629+08:00 stdout F Log message 4 2024-11-07T18:46:10.776122173+08:00 stdout F Log message 5 2024-11-07T18:46:11.778271688+08:00 stdout F Log message 6
K8s 1.29及以上版本
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
data:
filebeat.yml: |
filebeat.inputs:
- type: log
paths:
- /stdout/*
output.elasticsearch:
host: '${NODE_NAME}'
hosts: '["https://${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}"]'
username: '${ELASTICSEARCH_USERNAME}'
password: '${ELASTICSEARCH_PASSWORD}'
protocol: https
ssl.certificate_authorities: [ "/usr/share/filebeat/certs/ca.crt" ]
---
apiVersion: batch/v1
kind: Job
metadata:
name: busybox-stdout
spec:
template:
spec:
initContainers:
- args:
- -e
- -E
- http.enabled=true
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: ELASTICSEARCH_USERNAME
valueFrom:
secretKeyRef:
key: username
name: elasticsearch-master-credentials
- name: ELASTICSEARCH_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: elasticsearch-master-credentials
image: mirrors-ssl.aliyuncs.com/docker.elastic.co/beats/filebeat:8.5.1
imagePullPolicy: Always
restartPolicy: Always # 聲明此容器為sidecar
name: filebeat
resources:
limits:
cpu: 250m
ephemeral-storage: 30Gi
memory: 512Mi
requests:
cpu: 250m
ephemeral-storage: 30Gi
memory: 512Mi
volumeMounts:
- mountPath: /stdout
name: stdout-log
readOnly: true
- mountPath: /usr/share/filebeat/certs/
name: elasticsearch-master-certs
- mountPath: /usr/share/filebeat/filebeat.yml
name: filebeat-config
readOnly: true
subPath: filebeat.yml
containers:
- name: busybox
image: mirrors-ssl.aliyuncs.com/busybox:latest
command: [ "sh", "-c" ]
args:
- |
for i in $(seq 1 100); do
echo "Log message $i"
sleep 1
done
volumes:
## 采集標準輸出日志
- emptyDir:
medium: Stdout
name: stdout-log
- name: elasticsearch-master-certs
secret:
secretName: elasticsearch-master-certs
- configMap:
name: filebeat-config
name: filebeat-config
restartPolicy: OnFailure
# 下面的配置只是單純?yōu)榱吮疚臋n的示例
# 在真實環(huán)境中需要替換為,部署EFK的時候自動生成的配置
---
apiVersion: v1
data:
ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJakNDQWdxZ0F3SUJBZ0lSQUl0SDZxR2YzRG9VNFBuVWRJOUdITlV3RFFZSktvWklodmNOQVFFTEJRQXcKR3pFWk1CY0dBMVVFQXhNUVpXeGhjM1JwWTNObFlYSmphQzFqWVRBZUZ3MHlOREV3TWprd056RTNNamxhRncweQpOVEV3TWprd056RTNNamxhTUJzeEdUQVhCZ05WQkFNVEVHVnNZWE4wYVdOelpXRnlZMmd0WTJFd2dnRWlNQTBHCkNTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFET1Zxc0svVXAvWTVNRVY5T3hzTUk2TTZMTFhYMGsKNFBGSjE0SklVNStUVnBRVVNhVmx3N0REeGtJaUQ3RDVHZ3I3Snh4WHV0cFNjVlo0QWN0UzNrNFJvV3lqdzg0cApoYW4wY3JZL2VaQmJlWjVFUUhCSXprU0ZhMWd4bkpUcVErSSsvR3lKSlNHNkQyR21UVHRqRXZ2R2pWL1loSDNHCk1DMnRadVNXN1hPYWZBKzFqWU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EMkgvOGZ6OEZPOU1NYjJ0TDNBTmEzVVhXWkFTUEZjT0R3V2JBZlVSZGo1bTZzYQpONE1pVm5HRUFHazc4bDJ1RnRpd3NrNkhsSUc2L2RLaWZlbUtkdzdxRHREMGc2bzBCeFk1MXlmejlwbXZhOHRXCmc4Y3FMUUhEdFFZY3VYUkhNcE1ZY2RrQ2dZRUFrZHdxbys5OEo3cDR1Rkg1T2xCZWtSVFZxOXpsWVNlOGFFSi8KS3BKTVFpVUNsekVqY0NnZ2xaRjF5NGZhZFo5b0l5OVhZZ29FVkZGbzl3WW9MeWNFdXdMM1lKV3laMHJtL01pegpNOWNzWG8raVhDV29taVRFUmx2SUZxQUNiVUtIazcvdWFTeFI0S3RKNzhNN2x2TW5Ea1pCRVJkQ0lVTklsNEp4CkhleDhsVlVDZ1lCdlVMQUU3WkMyTkFnZUpYUmpRalFRd2laNU1jS09rTTBvVjlsYUlaR0xZUUVTOHVtYXA0THYKMVc5clN4UElxMTg3Q1haejBuOTdPN210aUpwYXhERDg1QVdZMEg5MGhFNitvZUltWmlPN3ZYbW5RTVRNZjNtWgp6dUcvNk84ckpsNWcyNnY4NTVBYjVUbC9ZQTNRcW1tOVdKdUt5eGw1bWxvMGkxNU14cWNia1E9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
kind: Secret
metadata:
name: elasticsearch-master-certs
type: kubernetes.io/tls
---
apiVersion: v1
data:
password: Z3BVMTFFZXZNWWFmMkVCUw==
username: ZWxhc3RpYw==
kind: Secret
metadata:
name: elasticsearch-master-credentials
type: Opaque
場景三:基于OpenKruise SidecarSet自動注入Sidecar容器
上述提供的方法需要Sidecar容器配置到每個工作負載當中,在工作負載比較多的情況下,會比較大的增加用戶的工作量。OpenKruise的SidecarSet提供了一種對Sidecar容器的管理能力,能夠自動注入和獨立升級Sidecar容器,進而做到一次配置自動注入的效果。詳細信息,請參見向虛擬節(jié)點中的Pod注入Sidecar容器。