Microservices are a specialisation of Service Oriented Architectures (SOAs). Their increased modularity and scalability are at the base of automated deployment practices like Continuous Deployment and Autoscaling. In this paper we provide formal foundation to these practices, showing that automated deployment, which was proved to be an undecidable problem in general, can be treated algorithmically when moving to microservices. The underlying assumption in our main result is that microservices have a configuration lifecycle based on two main phases: (i) creation and initial connections with already available microservices and (ii) subsequent binding/unbinding with other microservices. We illustrate the applicability of our approach by showing an automatic optimal deployment tool applied to a realistic microservice architecture modeled in the Abstract Behavioural Specification (ABS) language.