India secured a hard-fought 17-run victory in the first ODI against South Africa, powered by Virat Kohli's 52nd ODI century.