1 Shane wanted to take Rick's place
Shane loved Lori and was shocked when Rick returned. He always wanted to take the place of Rick especially after he left.
2 Rick started distrusting Shane
Rick started becoming uncomfortable around Shane as he no longer trusted him. This resulted in a lot of tension.
3 Shane tried to kill rick
Shane tried to kill Rick twice. It was clear to Rick that he must get rid of him sooner or later.
4 Shane became a threat
As Shane's intentions weren't that clear Rick realized that Shane became a threat. It was clear that he will have to get rid of him one day.
5 To defend himself
Shane lured Rick away to kill him. Rick pulled his knife in the last moment and did it first. See Why the Walking dead is so Popular.