Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling cronjobs in a Pod with multiple containers

I have a requirement in which I need to create a cronjob in kubernetes but the pod is having multiple containers (with single container its working fine).

Is it possible?

The requirement is something like this: 1. First container: Run the shell script to do a job. 2. Second container: run fluentbit conf to parse the log and send it.

Previously I thought to have a deployment in place and that is working fine but since that deployment was used just for 10 mins jobs I thought to make it a cron job.

Any help is really appreciated.

Also about the cronjob I am not sure if a pod can support multiple containers to do that same.

Thank you, Sunny

like image 949
sunnybhambhani Avatar asked May 04 '20 12:05

sunnybhambhani


1 Answers

Yes you can create a cronjob with multiple containers. CronJob is an abstraction on top of pod. So in the pod spec you can have multiple containers just like you can have in a normal pod. As an example

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: default
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          - name: app
            image: alpine
            command:
            - echo
            - Hello World!
          restartPolicy: OnFailure
like image 168
Arghya Sadhu Avatar answered Oct 25 '22 03:10

Arghya Sadhu