Essentially, enough energy is created to produce just enough pressure to balance gravitational collapse. Too much energy output produces too much pressure, which leads to expansion, which cools the star slightly, which reduces the energy production, and so the regulation. Likewise, too little energy output produces too little pressure, which leads to gravitational contraction, which raises the temperature, which increases energy production, and so the regulation. And when the star ages, and the nuclear fusion reactions become inefficient, it is the breakdown of this thermostatic regulation that causes the death of the star. Mass and energy must be spread smoothly throughout the star.
Energy can flow outward only by conduction, convection, or radiation.
These laws are expressed as differential equations, and calculations of stellar structure involve the solution of a system of four simultaneous differential equations, a so-called fourth order system. The more massive a star is, the more weight it must support, and the higher its internal pressure must be. To keep its pressure high, the massive star must be hot and generate large amounts of energy. Thus the mass of a star determines its luminosity. The more massive a star is, the faster it uses up its hydrogen fuel.