If the ant is stinging, then there is no problem in killing it and if it is not stinging, then killing it is Makruh (Undesirable). As given in (Fatawa A’alamgiri, Vol. 5, Pg. No: 361)
The ‘Ulama are in difference of opinion on this. The preferred opinion is that if the ants are not stinging, then killing it is Makruh and they are in agreement that it is Makruh to put ants in water.
Killing them without a reason is that the ants perform Tasbeeh of Allah Ta’ala.
There is a (Hadith in Zujajatul Masabeeh, Vol. 3, Pg. No: 319)
Translation of Hadith: It has been narrated on the authority of Hadhrat Abu Hurairah (May Allah be well pleased with him) that the Holy Prophet (Sallallahu alaihi wa sallam) said: An ant stung a Prophet. He ordered that the ants should be killed. The colony of those ants was burned. Allah Ta’ala sent him a Wahi (revelation): Only 1 ant had stung you, but you burned such an Ummah among the Ummahs, which used to perform Tasbeeh of Allah Ta’ala.