Conditioned deploy

hi,
how should i deploy application with 2 replicas and database with 2 instances?Let`s say we have 4 workers.
I like to deploy 2 application replicas on worker 1 and worker 2 and 1 db instance on worker 3 and the other db instance on worker4.