Version: v1.2

Attaching Sidecar

The sidecar trait allows you to attach a sidecar container to the component.

How to use

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.

  1. # app.yaml
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: vela-app-with-sidecar
  6. spec:
  7. components:
  8. - name: log-gen-worker
  9. type: worker
  10. properties:
  11. image: busybox
  12. cmd:
  13. - /bin/sh
  14. - -c
  15. - >
  16. i=0;
  17. while true;
  18. do
  19. echo "$i: $(date)" >> /var/log/date.log;
  20. i=$((i+1));
  21. sleep 1;
  22. done
  23. volumes:
  24. - name: varlog
  25. mountPath: /var/log
  26. type: emptyDir
  27. traits:
  28. - type: sidecar
  29. properties:
  30. name: count-log
  31. image: busybox
  32. cmd: [ /bin/sh, -c, 'tail -n+1 -f /var/log/date.log']
  33. volumes:
  34. - name: varlog
  35. path: /var/log

Deploy this Application.

  1. vela up -f app.yaml

Use vela ls to check the application state:

  1. $ vela ls
  2. APP COMPONENT TYPE TRAITS PHASE HEALTHY STATUS CREATED-TIME
  3. vela-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.

  1. vela logs vela-app-with-sidecar -c count-log
  1. 0: Fri Apr 16 11:08:45 UTC 2021
  2. 1: Fri Apr 16 11:08:46 UTC 2021
  3. 2: Fri Apr 16 11:08:47 UTC 2021
  4. 3: Fri Apr 16 11:08:48 UTC 2021
  5. 4: Fri Apr 16 11:08:49 UTC 2021
  6. 5: Fri Apr 16 11:08:50 UTC 2021
  7. 6: Fri Apr 16 11:08:51 UTC 2021
  8. 7: Fri Apr 16 11:08:52 UTC 2021
  9. 8: Fri Apr 16 11:08:53 UTC 2021
  10. 9: Fri Apr 16 11:08:54 UTC 2021

Specification

  1. vela show sidecar
  1. # Properties
  2. +---------+-----------------------------------------+-----------------------+----------+---------+
  3. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  4. +---------+-----------------------------------------+-----------------------+----------+---------+
  5. | name | Specify the name of sidecar container | string | true | |
  6. | cmd | Specify the commands run in the sidecar | []string | false | |
  7. | image | Specify the image of sidecar container | string | true | |
  8. | volumes | Specify the shared volume path | [[]volumes](#volumes) | false | |
  9. +---------+-----------------------------------------+-----------------------+----------+---------+
  10. ## volumes
  11. +-----------+-------------+--------+----------+---------+
  12. | NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
  13. +-----------+-------------+--------+----------+---------+
  14. | name | | string | true | |
  15. | path | | string | true | |
  16. +-----------+-------------+--------+----------+---------+