30 minutes ago I had a root canal treatment for my upper teeth and now am experiencing a headache…Do I need to take some medicine?

Yes, it would help. It would be a good idea to take what ever you normally take for your headaches. Just the stress of having endodontic treatment can induce your headache and some local anesthetics can cause a headache as well. Good luck and feel better!
Take OTC Pain relief. The nature of root canal treatment requires patients to keep their mouth open for extended periods of time. This stretching of the muscle can lead to a headache. Simple over the counter pain medications will usually relieve the pain. If it continues be sure to call your treating dentist to advise of your condition. Good news - it is a temporary condition.
Postoperatory pain. The most likely reason you had root canal treatment was because an infected tooth. Once you start the treatment the pain generally diminishes but can still continue. Generally the treatment requires several session. Meanwhile you should consult with the treating dentist for the need for antibiotics or pain medication or both.