There’s plenty of money in it. Even if the ads were minimally personalized (ie use location so that when I search for a plumber I see local plumbers) just the keyword-based ads would probably be enough to cover the costs. Apple users are exactly who advertisers want to reach.
Apple has shown in the past that if something is considered a key technology, they would rather own it than hand that power to a key competitor. They made their own CPUs, they made Maps, and they could make search.