A covalent bond is formed between two non-metals that have similar electronegativities.
An ionic bond is formed between a metal and a non-metal. Non-metals(-ve ion) are "stronger" than the metal(+ve ion) and can get electrons very easily from the metal. These two opposite ions attract each other and form the ionic bond.