Golang application for kubernetes
I want to develop a Golang application for Kubernetes (cloud-native). So, I have a question about application architecture for DevOps.
First, need to say a little bit of information about the application. The application is a usual rest API server that uses cron commands and workers. In the feature, I will deploy the rest API server and workers via Kubernetes Deployment, for cron commands will use CronJob. However, I didn't decide how to build docker images for deploying my application.
So, about problems:
In my project, a have hext applications:
/cmd/
|---/api/
|--- main.go
|---/cron
|--- main.go
|---/worker
|--- main.go
I will develop worker and cron as command-line application using package flag.
Database migrations
I think that need to build other Docker image for migration only. For example with using base image migrate/migrate.
Running commands / workers
I will develop cron and worker as console commands that need to run in Kubernetes as commands in Docker containers like this.
Running the Rest-API server
I will run rest API server in scratch container like this:
FROM scratch
COPY --from=Builder /main /
EXPOSE 8080
CMD ["/main"]
So, when I use this decision need to build 3 Docker containers. It's okay?
One of the best decisions it adds all applications in one Docker container and executes applications as a command line.
But, I like it when in the Docker image exists only one application with dependencies.
What do you think about it?