The way to do this is to define a new function

Your original function is

Your constraint is

So you form a new function

Now find the partial derivatives w.r.t x and y and set them to zero

Now you want to eliminate lambda. So you multiply the second equation by k as add them to give

And finally you substitute from your constraint y = kx to give

which simplifies to

Lastly you need to find the y which can be found by substituting in the constraint (y = kx) therefore

Hope this helps. Lagrangian multipliers are very useful devices and come up in lots of interesting places.