Why your gas hot water heater pilot keeps going out can be caused by many reasons which will require troubleshooting to find the reason or, reasons why it is going out. Once the problem causing the pilot to go out has been corrected the pilot should stay lit and reliable water heating should return to your home.
One of the more common causes is a thermocouple which has failed. The thermocouple is a bimetal part that when placed in a pilot flame heats and produces a voltage which activates a magnet in the gas valve of the hot water heater. This valve allows the gas to flow to the pilot and main burner of the water heater shutting off if the pilot flame were to go out providing safety from what could be a deadly buildup of gas.
In some water heaters a thermopile may be used which provides a higher voltage that can actually operate an electronic control board. Some other water heaters also used a one time thermal fuse built into the thermocouple which could detect an event where the pilot flame burned higher due to flammable gas vapors in the air drawn into the water heater burner and shut the water heater down. Consult the manual for your water heater to determine what you have installed and how to troubleshoot the thermocouple.
Some of the other possible causes of a hot water heater pilot going out could include a weak magnet in the gas valve, improper or, intermittent gas pressure, lack of combustion air, and improper venting. Also on the newer Flammable Vapor Ignition Resistant (FVIR) the pilot going out could be caused by an FVIR event or, a clogged flame arrestor, again consult your water heater manual for troubleshooting information.