There are two counters on each ship: Deployment clock and Maintenance Clock. Both count up at the same rate while a ship is flying around.
Being at a recreation location (population of (I think) 50k or more, or a recreation module), will cause the Deployment Clock to count back down to zero. If the deployment clock goes over the ships designed deployment period, morale starts to drop.
Being at a maintenance location with sufficient capacity (either staffed maintenance facilities at a population, or maintenance modules on ships or stations), will cause the Maintenance Clock to stop increasing. Maintenance locations also allow a ship to go into Overhaul, and start reducing the Maintenance Clock, at the cost of MSP.
Maintenance modules do not need to be at a population. Neither do recreation modules. Using both allows creating a deep space location that can allow ships to reset both clocks, but you will need to freight in MSP for the maintenance modules.