Attaching Sidecar Container
The sidecar trait allows you to attach a sidecar container to the component.
In this Application, component log-gen-worker and sidecar share the data volume that saves the logs. The sidebar will re-output the log to stdout.
# app.yamlapiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: vela-app-with-sidecarspec:components:- name: log-gen-workertype: workerproperties:image: busyboxcmd:- /bin/sh- -c- >i=0;while true;doecho "$i: $(date)" >> /var/log/date.log;i=$((i+1));sleep 1;donevolumes:- name: varlogmountPath: /var/logtype: emptyDirtraits:- type: sidecarproperties:name: count-logimage: busyboxcmd: [ /bin/sh, -c, 'tail -n+1 -f /var/log/date.log']volumes:- name: varlogpath: /var/log
Deploy this Application.
vela up -f app.yaml
Use vela ls to check the application state:
$ vela lsAPP COMPONENT TYPE TRAITS PHASE HEALTHY STATUS CREATED-TIMEvela-app-with-sidecar log-gen-worker worker sidecar running healthy 2021-08-29 22:07:07 +0800 CST
And check the logging output of sidecar.
vela logs vela-app-with-sidecar -c count-log
expected output
0: Fri Apr 16 11:08:45 UTC 20211: Fri Apr 16 11:08:46 UTC 20212: Fri Apr 16 11:08:47 UTC 20213: Fri Apr 16 11:08:48 UTC 20214: Fri Apr 16 11:08:49 UTC 20215: Fri Apr 16 11:08:50 UTC 20216: Fri Apr 16 11:08:51 UTC 20217: Fri Apr 16 11:08:52 UTC 20218: Fri Apr 16 11:08:53 UTC 20219: Fri Apr 16 11:08:54 UTC 2021
Last updated on Feb 9, 2023 by dependabot[bot]