Replacing a thermocouple connected to a pilot light involves taking the entire burner and thermocouple assembly, and then unhooking the thermocouple. Take it with you to the home improvement store to ensure that you purchase the correct replacement.
To start the process, turn off the gas valve that allows gas into the water heater, as well as the valve on the gas line near the wall. Consult your owner's manual for the location of the thermocouple assembly, and then take out the nuts that fasten the gas tubes and thermocouple to the valve. The burner generally sits or has clips holding it in the burning chamber and often just slides out. While the burner is out, vacuuming the compartment improves overall efficiency, and taking debris out of the burner ports and looking for any signs of leaks.
After you've removed the old, faulty thermocouple, simply reverse the process to put the new one in. Next comes reinstallation of the burner assembly. Reattach the thermocouple, and put the burner back like it was, and turn the pilot back on. To check for gas leaks, apply soapy water to several joints in the plumbing while the main burner is operating. Any bubbles that show up indicate that the system is leaking gas.