The most common cause of smelly water in a water heater is the presence of anaerobic bacteria. This problem is typically recognized by a smell resembling that of rotten eggs.
The smell is created when the anaerobic bacteria reacts with sacrificial anodes made of magnesium and aluminum in the water heater. This problem is not caused by any defect in the water heater, but is simply more common with water in certain regions and in some well systems. The anodes cannot be removed because the water heater will rust.
A short-term solution is to drain some water from the tank and add some hydrogen peroxide, then run the taps for a short time. The peroxide kills the bacteria, but they may begin to populate again if the water heater sits idle for several days.
The long-term solution is to have the sacrificial anodes replaced with a zinc and aluminum alloy. This method may not work if a water softener is present, however. In these cases, a powered anode may be required. It may also be possible to add a tee to the hot port of the water heater to make it easier to regularly add hydrogen peroxide to combat the problem.