Lymph nodes contain white blood cells called B cells and T cells. These are cells of the adaptive immune system. They are the immune systems most efficient killers but need some time to get going.
The adaptive immune cells need to be shown the infection by another cell of the immune system called a dendritic cell. Dendritic cells have to find the infection and then travel to the nearest lymph node to find the best B and T cell to fight off the infection.
Once the Dendritic cell has found that B cell and T cell, the T and B cells expand rapidly to build an army to fight off the infection and leave the lymph node. We feel this expansion as swelling in our glands (like tonsils for example).
Some of the B and T cells hang around after the infection clears and become memory B and T cells, which help us fight off the infection faster if we encounter it again.