A reliability system submitted to external and internal failures, that can be repairable or non-repairable, with degradation levels, and with sojourn times phase-type distributed, is considered. Repair is not as good as new, and the repair of internal failure follows policy N, that is, after N completed repairs the system is replaced by a new one to the following failure, repairable or not. For this system, a Markov model is constructed, and the stationary probability vector is calculated. It is shown that the distribution of the time between two consecutive replacements follows a phase-type distribution, whose representation is determined. The costs of these periods are calculated. An optimization problem involving the costs, the availability, and the number of internal repairs is illustrated by a numerical example.