You might expect that the original pork barrels were barrels for storing pork — and you’re right. In the early 19th century, that’s exactly what ‘pork barrel’ meant.
But, the term was also used figuratively to mean ‘a supply of money’ or ‘one’s livelihood’ (a farmer, after all, could readily turn pork into cash).
When 20th-century legislators doled out appropriations that benefited their home districts, someone apparently made an association between the profit a farmer got from a barrel of pork and the benefits derived from certain state and federal projects. By 1909, ‘pork barrel’ was being used as a noun naming such government appropriations, and today the term is often used attributively in constructions such as ‘pork barrel politics’ or ‘pork barrel project.’