Why does a surge occur? Perhapsa you have other devices on the other USB ports like external hdd, iphone charging, printer, tablet, etc. The usb ports have a limited supply so if a high power device requires more then other usb ports will reduce in power or become unavailable for use.
Usually though, if the keyboard is conecting/reconnecting/disconnecting then it is possibly a loose in the cable of the keyboard. Consider using a wireless keyboard.
Only use USB 2.0 ports for mice and keyboards.