Why do covalent compounds follow the octet rule?
By sharing one or more electrons.
Let's take Fluorine (F). It has 7 electrons in its outer shell, but it "wants" to have 8 (the octet rule). Now with another F-atom it can share one electron each, and "pretend" they both have 8.
My chemistry teacher used to explain this by analogy: if two polar bears both have a bald patch of skin, they can put these bold patches against each other, and both stay warm.