The most common reason is as a result of a middle ear infection. Oftentimes when the acute infection which is causing pain or discomfort, is resolved, there will be leftover fluid that doesn't drain from your middle ear. And it doesn't drain because your eustachian tube is swollen closed.
This is usually treated with various anti-inflammatory drugs. But on occasion those drugs are not effective and the fluid must be surgically drained. This fluid is drained by making a small hole in the eardrum, which is called a myringotomy. This is a procedure that can be done on an adult in the office painlessly with a topical anesthetic.
Young children, however, who will not hold still in the office, often need to be sedated in the operating room with a light general anesthetic.