Turkey is a NATO member — and so, by treaty, an American ally. Yet Turkish President Recep Tayyip Erdogan sure didn't sound like one on during a Thursday: He blamed the United States for, among other things, turning the Middle East into "a sea of blood."

This all comes back to a big disagreement over one of Syria's most important issues: the Kurds.

Kurdish militias in northern Syria have proven to be one of most successful battlefield forces fighting ISIS; the United States sees them as among its most effective partners in the country.

At the same time, Turkey's long-running conflict with Kurdish insurgents inside its own border has become increasing violent, with hundreds dying in the past few months. The Syrian Kurds have a tight relationship with their kin across the Turkish border; Turkey believes the US policy in Syria amounts to funding and arming an anti-Turkish terrorist group.

As a result, two major allies in the fight against ISIS are at odds with each other — a neat illustration of the big-picture reasons the fight against ISIS is, and will remain, so difficult.

Why Turkey and the US are at odds over the Kurds

Turkey has long had a major problem with its Kurdish insurgency, concentrated near the Syrian and Iraqi borders, especially the Kurdistan Workers' Party (PKK).

The PKK is a Kurdish nationalist group founded in 1978 that seeks autonomy for Turkey's ethnic Kurdish minority. Over the past decades, fighting between the PKK and Turkey has killed about 40,000 people, with violence peaking in the 1990s.

When the Syrian civil war began heating up in 2012, the Turkey-PKK conflict was at that point cooling. Erdogan opened up negotiations with the PKK that year, and eased some (though far from of all) of the country's infamous restrictions on Kurds. A ceasefire took hold in 2013, and it looked like it might develop into real peace.

But the situation in Syria complicated that. Syrian Kurds essentially seceded from the country in 2012. They created a de facto autonomous Kurdish state, called Rojava, and set up a military force — the People's Protection Units (PYD) — to defend it.

That "changed the game, for Turkey and for Kurds," Atlantic Council Turkey expert Aaron Stein told me last year. Turkey worried that Syrian Kurds would inspire Kurdish nationalism in Turkey and that Turkish Kurds would use this de facto mini state as a base of operation.

In 2013 ISIS began attacking Syrian Kurdish territory, yet Turkey's government refused to lift a finger to help — leading some Turkish Kurds to speculate that Turkey was willing to tolerate ISIS attacks against Kurds.

This became a problem for US-Turkey relations in June 2014, when ISIS swept across most of northern Iraq. US policymakers, looking for allies on the ground in Syria to push against ISIS there, settled on the Kurds as the most reliable and willing.

It worked: American bombs helped break the siege of Kobane, a Kurdish city in northern Syria besieged by ISIS, in January 2015. Shortly thereafter, Syrian Kurdish (PYD) troops swept ISIS out of much of northern Syria.

But in July 2015, while the US was publicly celebrating PYD advances, PKK-Turkish tensions erupted into low-level warfare. The PKK blamed Turkey for an ISIS suicide bombing in its territory and retaliated by killing two Turkish policemen. This fighting has gone on, unabated, since then.

So from Turkey's point of view, the US support for PYD is effectively helping to create a safe haven for a hostile terrorist group on Turkey's border and exacerbating the PKK conflict. The United States, for its part, is unwilling to give up on its most reliable ally in Syria, seeing ISIS as a much greater threat to regional stability than the PKK or PYD.

This has led to a lot of behind-the-scenes tension between the US and Turkey, which had previously disagreed over the Syrian conflict. (Turkey wanted the US to more aggressively confront Syrian leader Bashar al-Assad.) That came to the fore with Erdogan's Thursday outburst.

"Are you on our side or the side of the terrorist PYD and PKK organizations?" Erdogan asked rhetorically. "Hey, America. Because you never recognized them as a terrorist group, the region has turned into a sea of blood."

This illustrates a fundamental problem in the war against ISIS

Take, for instance, the oft-proposed idea of carving out a "safe zone" in northern Syria. The idea would be to create a space where civilians could live free of war, and where anti-ISIS forces would be free to train with US and allied experts. Indeed, the US and Turkey very nearly agreed on a plan to create such a zone last July.

To make this idea work, you'd need ground troops to defend the safe zone from ISIS and from regime forces. The US isn't interested in putting its own ground troops in harm's way. But the Kurds have objected vociferously to using Turkish troops or Turkish-backed Syrian rebels: They believe Turkey will intentionally select territory that would obstruct PYD military advances.

This puts America in a bind: Any plausible anti-ISIS safe zone would require Turkish buy-in, but a Turkish-backed safe zone would alienate the Kurds, whom America also needs. Turkey and the Kurds are too focused on one another to put aside their differences to fight ISIS.

This is a part of a wider problem whereby the United States is perhaps the only member of the anti-ISIS coalition whose principal objective is fighting ISIS:

Syrian Arab rebels are principally interested in fighting Bashar al-Assad; Assad is principally interested in fighting the rebels.

Saudi Arabia and Iran are struggling against one another's influence in Syria. That means Saudi Arabia is backing the anti-Assad rebels rather than groups focused on ISIS, while Iran is backing the regime against its rebel opponents.

Russia sees Assad as a core ally, and hence cares far less about weakening ISIS than about destroying the rebels who pose the greater threat to him.

Kurds are only fighting ISIS to protect their own territory; Turkey is principally interested in weakening Kurdish influence (and toppling Assad). Neither wants to take and hold ISIS-held territory, which is mostly Arab.

"All of our allies and rivals have far more complex goals than degrading and defeating the Islamic State," Michael Knights, an Iraq expert at the Washington Institute for Near East Policy, wrote in a December War on the Rocks piece. "For them, the current battle is really a game of positioning for the truly decisive action that will begin as soon as the Islamic State is defeated."

For the United States, managing all this is like herding cats. Whatever policy it proposes to try to fight ISIS gets twisted by its allies' interests. Since the United States can't defeat ISIS alone, this is a fundamental problem for the anti-ISIS war: America's key partners are focused on other enemies.

Erdogan's colorful outburst, then, wasn't just a random bit of rage — it was an example of one of the biggest (and possibly unsolvable) problems the US is facing in its war on the Islamic State.