It depends what context you use them in but generally this is what they mean:
Sample = A small piece or part of something that is used to show what the whole piece is like. For example, if you wrote an essay you could read out a 'sample' of it.
Pattern = A repeated way that something is done. For example, if you drew a square then a triangle and repeated doing so, it would be a pattern.
Template = A shaped piece of material used as a pattern for processes such as cutting out, shaping, or drilling