通过Sidecar采集日志
可通过hostpath-replacement将hostPath替换为CCI支持的emptyDir,通过pod-sidecars注入日志采集Sidecar,通过mount-stdlog-containers使日志采集Sidecar容器增加容器标准输出日志挂载。
前提条件
通过Sidecar采集日志前,您需要先参考配置Sidecar工具容器章节配置Sidecar工具容器。
约束与限制
“volume.cci.io/mount-stdlog-containers”和“volume.cci.io/mount-stdlog-containers-path”不支持同时配置。
通过YAML创建
apiVersion: apps/v1 kind: Deployment metadata: labels: version: v1 bursting.cci.io/burst-to-cci: enforce name: deploy-example namespace: default spec: replicas: 1 selector: matchLabels: app: deploy-example version: v1 template: metadata: annotations: bursting.cci.io/hostpath-replacement: '[{"name":"log","policyType":"replaceByEmptyDir","emptyDir":{"sizeLimit":"10Gi"}}]' bursting.cci.io/pod-sidecars: '{"containers":[{"name":"log-sidecar","image":"fluent-bit:latest","resources":{},"volumeMounts":[{"name":"log","mountPath":"/tmp/log"}],"position":"tail"}]}' volume.cci.io/mount-stdlog-containers: log-sidecar #指定需要挂载容器标准输出日志的容器名 labels: app: deploy-example version: v1 spec: containers: - image: nginx:latest name: nginx resources: limits: cpu: "1" memory: 2Gi requests: cpu: "1" memory: 2Gi volumeMounts: - mountPath: /tmp/log name: log imagePullSecrets: - name: default-secret volumes: - hostPath: path: /local/log name: log
通过以上方式配置,Sidecar工具容器可采集的日志可以分为以下两种:
- 标准输出。业务容器的标准输出日志会被挂载到/var/log/pods路径下,Sidecar可以以文件的方式收集业务容器的标准输出日志。
- 文件日志。业务容器将日志文件输出到和Sidecar共享的Volume中,Sidecar可以收集对应Volume内的文本文件。
Pod的注解 |
参数类型 |
描述 |
示例值 |
---|---|---|---|
volume.cci.io/mount-stdlog-containers |
String |
|
示例一: "container-0,container-1" 示例二: "*" |
volume.cci.io/mount-stdlog-containers-path |
String |
|
示例一: "{\"container-0\":\"/var/log/pods\",\"container-1\":\"/tmp/log/pods\"}" 示例二: "{\"*\":\"/tmp/log/pods\"}" |