The Internet of Things is a technological revolution that is transforming several application domains. It has brought a number of solutions and alternatives and is one of the pillars of Industry 4.0. Since several current and future IoT applications will require near-zero communication latency, Fog computing was recently proposed as an extension of the Cloud paradigm to the edge of the network. In the collaborative scenario envisioned by Fog computing, a fog controller is an entity responsible for mapping end-user service requests into the most suitable resources at the edge of the network. However, given the high dinamicity and heterogeneity perceived in this scenario, we argue for the benefits of the dynamic deployment of fog controllers (Control-as-a-Service) according to, for instance, the amount of underlying resources and their characteristics. This work introduces a rank-based weighted distributed algorithm that considers distinct characteristics of interest to select nodes capable of playing the controller's role at the edge of the network. In the performed experiments, we analyze the convergence time of the proposed algorithm and compare the frequency on controller changes in our approach with an adapted version of the well-known LEACH protocol, which was tailored to fulfill our scenarios' demands. In four distinct scenarios, the results show a reduction range varying from 68% to 95% on the frequency for selecting new controllers when comparing our proposal to the comparative method. Furthermore, the average latency for selecting the controller is low even in scenarios with increased number of candidates.