The thermocouple is a safety device that turns off the gas if there is no pilot light. If you look closely at the burning pilot light, there is a small metal tube that sits directly in the flame, with wires that lead back to the gas valve. The thermocouple generates a small amount of electrical current when heated by the flame. This current keeps the gas safety valve open. If the pilot light gets blown out, the current stops and the gas valve closes. When you light the pilot light, you hold down the over-ride button for about 30 seconds. This allows the gas to flow long enough to heat up the thermocouple and generate current and then you can release the over-ride button and gas will continue to flow. If the thermocouple is defective, then as soon as you release the over-ride button, since there is no electrical current, the gas will stop flowing and the pilot light will go out instantly or sometimes in few minutes.
This is a pretty common failure on water heaters and furnaces. Replacement of the thermocouple is fairly simple if you are the handyman type. If not, the thermocouple is a cheap part -- about $10 bucks, In some cases replacing thermocouple does not helps, in that case the gas valve is faulty and it has to be replaced.Thanks.