According to About.com, if the thermocouple does not reach the correct temperature, a safety valve stops the gas from flowing and extinguishes the flame. One common cause of this problem is owners who do not follow the manufacturer's directions for lighting the water heater pilot. Most require holding in the button or dial for approximately 30 seconds to allow the flame to heat the safety device before releasing it.
If the flame goes out again, About.com recommends waiting a few minutes for any accumulated gas to clear the area. Then, follow the lighting procedure again while depressing the button or knob for 45 seconds to a full minute. The next step is replacing the thermocouple if the unit continues to go out after several attempts to light it. The procedure to replace this unit is a simple one requiring the removal of a couple of screws. The home improvement store needs the manufacturer name and model number to ensure owners receive the correct thermocouple. If this does not stop the problem, SFGate recommends calling a professional to replace the valve, "since it involves breaking and resealing important gas connections."
While the Water Heater Repair Guide agrees the thermocouple is the most likely cause of the problem, it also identifies a drafty location as a potential cause. Some attic fans create a big draft that is strong enough to extinguish the flame. Wind gusts through a vent are another potential culprit on gusty days.