How does a phase difference of $\pi$ come between the incident and reflected ray? Well, I know that when an EM wave is incident on a surface and it reflects then a phase gap of $\pi$ comes between both the waves. I want to know the reason behind how the $\vec E$ component and $\vec B$ component behave in that very small time when they are in reflecting medium (or how medium acts). I would be thankful if someone could explain its effect on the wave propagation vector $\vec K$ and the Poynting vector $\vec S$.
 A: This typically happens at a perfectly reflective surface, with the 180 deg shift in E field if the surface is a smooth perfect conductor or "electric wall" (equivalent to a short circuit), and in H field if the surface is a perfect "magnetic wall" (which doesn't naturally exist, but can be equivalent to open circuit and approximated by some special structures). Let's talk about the E field case, since the H field case follows a similar treatment if the surface is changed. Furthermore, to make the discussion definite, let's talk about a plane way impending upon the surface. This will not lose generality, since any radiated wave can be thought of as a superposition of plane waves.
The reason behind your observation is that the boundary condition at a smooth perfect conductor forces the tangential E field to be zero at the surface. How can the field on one side of the surface achieve that? Say the wall exist in a Cartesian 3D, filling the half space $x>0$, and imagine a plane wave incident onto such surface from the left (either right angle incidence or obliquely). Then in the region $x\leq 0$ we have both the incident and reflected electric fields $\vec{E}_{tot}=\vec{E}_{inc}+\vec{E}_{ref}$. Their components tangential to the surface, say along $\hat{y}$, will therefore be
$$ E_{y,tot}=E_{y,inc}+E_{y,ref},$$
which must be now forced to zero. This can only be achieved if $E_{y,inc}=-E_{y,ref}$, which gives the 180 deg shift that puzzled you. You can now extend this to the H field using similar steps.
The $\vec{k}$ of the incident field will be reflected off such surface according to Snell's law, which still holds -- you should not confuse the direction and angle of incidence/reflection with the polarization of the field. For example, in the example above, the tangential E field component was polarized along the $y$ direction, but the wave itself could be landing obliquely upon the surface. So, the reflected direction, $\vec{k}_{ref}$ will follow from the right hand rule for $\vec{E}_{ref}\times \vec{H}_{ref}$ after you have worked out their 180 deg shifts in the tangential components. The incident wave had $\vec{k}_{inc}$ worked out similarly using the right hand rule for $\vec{E}_{inc}\times \vec{H}_{inc}$. The Poynting vector into the perfect conductor will be zero, since the field could not penetrate it, whereas on the other size, it has the same direction as $\vec{k}_{inc}$ or $\vec{k}_{ref}$. The Poynting vector into the surface can only exist if the wave could penetrate it, which will imply a surface that is not perfectly conducting, and therefore the phase shift will not naturally be 180 deg exactly (which is different from your question's premise). Such case is the case of non-perfectly-conductive surfaces, like resistive walls, for example, which exist naturally in most material.
