How do I run a cron inside a kubernetes pod/container which has a running spring-boot application?

2/26/2019

I have a spring-boot application running on a container. One of the APIs is a file upload API and every time a file is uploaded it has to be scanned for viruses. We have uvscan to scan the uploaded file. I'm looking at adding uvscan to the base image but the virus definitions need to be updated on a daily basis. I've created a script to update the virus definitions. The simplest way currently is to run a cron inside the container which invokes the script. Is there any other alternative to do this? Can the uvscan utility be isolated from the app pod and invoked from the application?

-- Zuke
cron
docker
kubernetes
spring-boot

3 Answers

2/26/2019

At my place of work, we also run our dockerized services within EC2 instances. If you only need to update the definitions once a day, I would recommend utilizing an AWS Lamda function. It's relatively affordable and you don't need to worry about the overhead of a scheduler, etc. If you need help setting up the Lambda, I could always provide more context. Nevertheless, I'm only offering another solution for you in the AWS realm of things.

-- Brandon
Source: StackOverflow

3/29/2019

So basically I simply added a cron to the application running inside the container to update the virus definitions.

-- Zuke
Source: StackOverflow

3/6/2019

There are many ways to solve the problem. I hope, I can help you to find what suits you best.

From my perspective, it would be pretty convenient to have a CronJob that builds and pushes the new docker image with uvscan and the updated virus definition database on a daily basis.

In your file processing sequence you can create a scan Job using Kubernetes API, and provide it access to shared volume with a file you need to scan.

Scan Job will use :latest image, and if new images will appear in the registry it will download new image and create pod from it.

The downside is when you create images daily it consumes "some" amount of disk space, so you may need to invent the process of removing the old images from the registry and from the docker cache on each node of Kubernetes cluster.

Alternatively, you can put AV database on a shared volume or using Mount Propagation and update it independently of pods. If uvscan opens AV database in read-only mode it should be possible.

On the other hand it usually takes time to load virus definition into the memory, so it might be better to run virus scan as a Deployment than as a Job with a daily restart after new image was pushed to the registry.

-- VAS
Source: StackOverflow