Slaves (in the days of slavery in the USA) used to hold competitions to see which couple could produce the most elegant walk. The best promenaders won a prize, almost always a cake. The extravagant walk required for this type of competition came to be called a Cakewalk and this gave rise to the old fashioned expression it's a cakewalk. However the meaning later came to emphasise the trivial nature of the competition and began to imply that the effort needed was minor and of little account. In consequence the modern saying it's a piece of cake could well be based on these old customs.
Alternative: In ancient Greek timesn a cake was a toasted cereal bound together with honey. It was given to the most vigilant man on night watch. Aristotle is quoted as having written in The Knights : if you surpass him in impudence, then we take the cake.