A water heater not staying lit can be cause by many reasons. The most common of which is a bad thermocouple or, one that has a loose connection at the gas valve. Sometimes too the thermocouple may not be properly placed in the pilot flame causing problems as well.
Other things that could cause the pilot not to stay lit include the magnet inside the gas valve getting weak so the thermocouple does not hold the valve open. On an older water heater replacement of the gas valve can be expensive and replacement of the water heater may be the best option.
If the gas pressure is insufficient or, fluctuates this may cause the pilot light to go out. Have you added any additional gas appliances lately?
Sometimes the combustion air supply can be inadequate especially if exhaust fans are involved. If the water heater is an FVIR (Flammable Vapor Ignition Resistant) design the flame arrestor can be plugged up with dust and lint. FVIR units may also have a thermal switch that requires resetting and in some cases a one time thermal fuse activates.
If the flue is improperly constructed or clogged with debris from animals, birds and insects the lack of venting can cause problems. In the winter snow may cover the vent.
On more complicated power vent and direct vent water heaters with electronic controls the trouble shooting gets more complicated and it is best to get a troubleshooting guide from the manufacturer.
Whatever cause exists, only troubleshooting and examining all the possible problems can allow you to find the problem and be able to fix it.