In a March 23 photo, US General David Petraeus, Commander of NATO International Security Assistance Force and US Forces Afghanistan, addresses Royal United Service Institute members on 'The Mission in Afghanistan' in London.

He's seen in some circles as having turned around the Iraq war, and was brought in to shore up the flagging NATO effort in Afghanistan last July. Now he is leaving to become chief of the CIA at a time when the theory of warfare he's put into practice in Afghanistan is coming under heavy strain from insurgents and an Afghanistan that grows ever more weary of foreign troops. The task his replacement will take up is looking as difficult as ever.

On the very afternoon that his departure for Washington was confirmed, horrifying scenes were unfolding in Kabul. There, eight US soldiers and one American contractor were gunned down by an Afghan Air Force officer in the military portion of the airport. The New York Times quoted an Afghan officer at the scene that other NATO soldiers leaped from second and third story windows to escape the killer.

That base is one of the most secure places in the country – yet US soldiers were literally forced to flee for their lives within it from one of their erstwhile allies. When I was in Afghanistan last summer, I went there to get my ISAF badge -- and had to wait outside the blast walls for an American private to come to me due to a "take no chances" approach to security there. But of course, there's no securing against betrayal by comrades you live and work with, as was amply demonstrated by Maj. Nidal Malik Hassan at Fort Hood last year.

Yet in Afghanistan, there are signs of betrayal within the Afghan military forces and police every day – sometimes of NATO forces, sometimes of their fellow citizens. These are the very forces that NATO is training, arming and paying. Nine days ago, a suicide bomber who belonged to the Afghan Army and was working with the Taliban infiltrated the Ministry of Defense in Kabul, his intended target apparently France's visiting Defense minister. The victims then were fellow Afghan soldiers. On April 16, five NATO and four Afghan soldiers were killed by a suicide bomber in uniform on their base in Laghman Province, and the day before that, police chief Khan Muhammad Mujahed of Kandahar was killed by a suicide bomber in police uniform.

Kate Clark, writing at the Afghanistan Analysts Network, says the Taliban had promised precisely this kind of infiltration at the beginning of this month. "Whether the Taleban are now changing their strategy – or just their messaging – is not yet clear," she writes. "However, his [Taleban spokesman Zabihullah Mujahid's] threat ... will be a major worry for the international and Afghan armies, as they race to get boots on the ground and have enough Afghan security forces ready to start taking over security, beginning with three provinces and four cities in summer 2011. The rapidity of the recruitment and training helps make forces vulnerable to such attacks."

What really happened in Kabul today? It will be days before we really know. Perhaps the Afghan pilot's murders were simply the result of snapping under a personal strain. Afghan officials say he quarreled with unidentified foreigners before his rampage. The Taliban, meanwhile, says the killer had converted to their cause and he was acting on their instructions.

But the simple facts are that such incidents are on the rise and violence has surged this spring compared with last spring. Though NATO and US briefings on Afghanistan seem to always emphasize "steady progress," the country remains as violent as ever and vaunted security gains seem tenuous. Even raw numbers on who's fighting with the US are unclear. The US Inspector General for Afghanistan Reconstruction said in a report on April 25, for instance, that the Afghan Interior ministry doesn't know how many police it employs, or how much of the money it pays in salary is actually being lost to fraud.

Take the jailbreak from Kandahar earlier this week. A team of Taliban spent months tunneling within firing distance of the city's main prison and one mile from the police headquarters, and their activities went completely unnoticed. Kandahar, the Taliban capital when the movement ruled Afghanistan, has been the focus of an intense US effort in the past couple of years. Billions of dollars have been spent on training local police and soldiers, developing intelligence networks and making infrastructure improvements in and around the city.

Yet no American drone spotted anything untoward. No friendly informant approached the US or Afghan authorities to say something suspicious was going on. And no one, absolutely no one, reported 550-odd Taliban fighters shuffling out of the prison through the tunnel a few nights ago. An inside job? Sure, probably. But the whole story, which has now put hundreds of motivated fighters, many of whom will be eager to kill US soldiers, back into play as the main fighting season begins, points to a city that is not exactly united in opposing the Taliban.

You would have to imagine the tunneling activity, which went on for months, would have yielded signs: Strange comings and goings, equipment being brought into a home, dirt being carried out. Yet none of it was reported by locals.

It's not just in the ethnically Pashtun south where the international coalition is facing problems. On April 1, the lightly guarded UN compound in the northern town of Mazar-i-Sharif was overrun by a mob enraged by an obscure American preacher's burning of a copy of the Quran on March 20. The mob murdered at least eight people inside, a number of them foreigners.

Afghan officials insisted the crowd had been infiltrated by the Taliban, who took advantage of what had been planned as a peaceful protest. But the Taliban don't really have much of a presence in Mazar, and strange Pashtuns from out of town quickly draw lots of attention. It's also interesting that the protest focused on the UN – a general symbol of the foreign presence in Afghanistan – rather than a symbol of the American presence. After all, the preacher who so offended the crowd was American.

While Muslim intolerance was the spark for the deaths, many analysts argue that if the foreign presence was generally seen as positive and healthy in Mazar, the UN probably would have been spared. And, of course, that whole tragic chapter wouldn't have been opened without the efforts of Hamid Karzai, the man who the US installed as Afghanistan's leader and whose reelection in a fraud-tainted process has been tolerated by NATO.

Illiteracy in Afghanistan is high, Internet access is very low. Almost no one in the country knew of the Quran burning in Florida until March 24, when Karzai put out a press release describing the burning as an attack on the global community of Muslims and appeared to demand the preacher be arrested and tried for his "crime."

Christine Fair, a Georgetown University professor who focuses on Afghanistan and Pakistan, writes that Karzai probably "chose this path of deadly controversy to demonstrate his strategic independence from the United States, which pays his bills while his supporters loot his country’s coffers.... Washington must ask if it can justify squandering such life and treasure on Karzai when he time and time again undermines his and America’s interests."

if the Wall Street Journal is right, Karzai may be exploring his own options. Members of his government anonymously told the Journal that he's being wooed by Pakistan Prime Minister Yousuf Gilani, who urged Karzai to ignore the US and "look to Pakistan – and its Chinese ally – for help in striking a peace deal with the Taliban and rebuilding the economy."

Petraeus came to the Afghanistan job at a time when the American project in Afghanistan was uncertain. His successor will be taking the job in much the same position.