Germany asked the Allies for an armistice (an agreement to stop fighting) rather than surrender, as they knew that they could no longer win the war, following a series of offensives earlier in 1918. They never anticipated that Germany would be blamed for starting the war (they didn’t) by France and Great Britain, to the point that such was claimed in the Treaty of Versailles, which formally ended the war.
As German forces had been pushed back all across the Western Front, German general Erich Ludendorff believed this was the only solution. Various German officials sought to blame their politicians for the failure, as they had claimed that the war would be over in Spring of 1918. The fact that both sides repeatedly claimed victory was just around the corner every spring of the war was ignored. Germany had also read the 14 Points speech of US President Woodrow Wilson and found it to be a better deal than the 8 Points from France. Unfortunately, Wilson’s points would not end up being the basis for the Treaty, especially the part about war reparations (payments for the cost) being prohibited.
This undue punishment and economic burden on Germany made life very difficult in the post-war, causing anger and allowing the rise of personalities like Adolf Hitler, who sought to take advantage of German bitterness over the Treaty terms.