Collecting Logs Using a Sidecar Container
You can use hostpath-replacement to replace hostPath with emptyDir supported by CCI, inject a sidecar container to collect logs through pod-sidecars, and mount the standard output logs to the sidecar container through mount-stdlog-containers.
Prerequisites
You have configured the sidecar container by referring to Configuring a Sidecar Container.
Constraints
volume.cci.io/mount-stdlog-containers and volume.cci.io/mount-stdlog-containers-path cannot be configured at the same time.
Using a YAML File
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 # Name of the container where standard output logs are to be mounted
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
With the preceding configurations, the sidecar container can collect two types of logs:
- Standard output logs. The sidecar container can collect the standard output logs of service containers as files and store these standard output logs to the /var/log/pods directory.
- File logs. Service containers output log files to the emptyDir volume shared with the sidecar container, which then collects the files from the volume.
|
Annotation |
Type |
Description |
Example Value |
|---|---|---|---|
|
volume.cci.io/mount-stdlog-containers |
String |
|
Example 1: "container-0,container-1" Example 2: "*" |
|
volume.cci.io/mount-stdlog-containers-path |
String |
|
Example 1: "{\"container-0\":\"/var/log/pods\",\"container-1\":\"/tmp/log/pods\"}"
Example 2: "{\"*\":\"/tmp/log/pods\"}" |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot