Step 1: What an earthquake can do
See how the water heater just falls over?
You might be thinking that if there's a strong enough earthquake to tip over my water heater, I've probably got bigger issues. Perhaps true, but I don't want to add fire from broken gas lines and flood from broken water lines into the mix.
You'll note in the pictures, I've already installed a flexible gas line, and semi-flexible water lines. The water lines are ribbed copper pipes that have some flex to them.
Step 2: Get a strapping kit
Here's the kit: It's essentially some metal straps and fittings.