In Kosovo, Serbia, Iraq, Afghanistan and now in Libya
Kosovo and Serbia were really the same case. But despite being on the Albanian side, I grant you that attacking Serbia over Kosovo with a goal to force independence for Kosovo was against international law.
Iraq was at war with the US and UK for a long time and there is no international law prohibiting an invasion of an enemy country.
Afghanistan... Either you accept the Taliban as the legitimate government, in which case Afghanistan had declared war on the US (and by extension on NATO) and invading Afghanistan was legitimate. Or you accept the pre-Taliban government as legitimate, in which case the invasion was legal since that government, represented by the Northern Alliance, was allied with the US. Or you accept the Soviet-communist government of Afghanistan as legitimate, in which case you might have a point. However, before that government came king Zahir Shah and he, of course, returned to Afghanistan with the invaders and supporting the government the invaders installed.
As for Libya, it depends on whether you recognise Gaddafi as the legitimate government or not. I don't. I only recognise the king until or unless the country becomes a true democracy and votes the king out of office.
However, I do find it strange, that a decision to stop Gaddafi from killing "civilians" somehow allowed NATO to help the rebels. Why didn't NATO decide to support the legitimate king and his followers? That would have been consistent.