I want to make a 4 legged robot like spider or dog, but I don't know how I can use kinematics to make it walk and run. I didn't find any resource to know how these types of robots walk and run by balancing their center of gravity balanced in each step and how they move their legs to move any direction. Right now I am trying to make a robot in gazebo simulation and test its working, only then I'll go for real hardware.
You do not (only) need inverse kinematics. Inverse kinematics can give you e.g. the angles in your leg joints for a particular leg position, however it does not define a gait type.
For 4 legged robots there are many possible gait types you can implement. You have static gait types where the projection center of gravity is always inside your support triangle and you only lift 1 leg up at at time, or you can have dynamic gait types which is the opposite (CoG not in support triangle, not only 1 leg lifted)
Simpler are the static gait types. For static gait types you have periodic, where you do the same steps over and over again or non-periodic, where leg placement is dependent e.g on ground conditions. Also here, obviously the periodic gait type is the simpler.