The Torah tells us that after the Mabul, Hashem decided that He would never destroy the world again by flooding it, and He emphasized the point by establishing a special covenant to guarantee it (א"י:ט תישארב). He then added that the rainbow which would periodically be seen in the clouds would serve as the symbol of this covenant (ז"י:ג"י םיקוספ םש). The Mishnah in Pirkei Avos (`ח הנשמ `ה קרפ) indicates that the rainbow actually existed long before the Mabul, having been one of the items created on Erev Shabbos just before nightfall of the first Shabbos in history. The Gemara in Berachos (.ט"נ ףד) states that one who sees a rainbow must make a Beracha, the text of which refers to the aforementioned covenant and also, as the Maharsha (יכורב ה"דב םש) points out, to this idea that the rainbow existed since the Sheishes Yemei Bereishis.
Rabbeinu Yehudah bar Yakar (a teacher of the Ramban) writes in his Peirush HaTefillos Vehaberachos (ח"נ דומע `ב קומע) that although the Pesukim imply that the rainbow "reminds" Hashem of His promise not to destroy the world when He seems to want to do so, Hashem, of course, needs no reminders because He forgets nothing. Rather, He is showing the people on earth who see the rainbow that there is too much wickedness in the world and that if not for His oath never to destroy the world, He would do so right then, just as He created and destroyed other worlds before this one existed, as mentioned in the Midrash (`ז ןמיס `ג השרפ הבר תישארב). Therefore, he adds, one ought to be inspired to do Teshuvah when seeing a rainbow. With this explanation in mind, perhaps, the Chayei Adam (`ד ףיעס ג"ס ללכ תוכרב תוכלה) cites an opinion that one who sees a rainbow should not tell anyone else about it because he would be spreading a negative report about the inhabitants of the world by publicizing that they deserve to be destroyed at the moment.
The Gemara in Chagiga (.ז"ט ףד) states that one who gazes at a rainbow displays disrespect for Hashem because the Posuk in Yechezkel (קוספ `א קרפ ח"כ) says that Hashem's appearance is somewhat similar to that of a rainbow (in the eyes of Yechezkel). The Gemara (םש) then adds that one's eyesight can fail if he gazes at a rainbow. The question may be raised as to how one can ever look at a rainbow and make the Beracha upon seeing it if it is improper to gaze at it altogether. The Beis Yosef (רוסא ה"דב ט"כר ןמיס ח"וא) quotes from the Avudraham that the Rosh was asked this question and responded that the "looking" necessary in order to require a Beracha is not the same as "gazing" which is considered inappropriate. Thus it is fine to see a rainbow and subsequently make the beracha; what is forbidden is staring at it with care and precision. The Tur (םש ח"וא) therefore writes that it is prohibited to stare at a rainbow; the Shulchan Aruch (`א ףיעס םש ח"וא) likewise prohibits gazing at a rainbow excessively. The G'ra (רתויב ה"דב םש א"רגה רואיב) stresses that one must see the rainbow in order to make the Beracha; the only prohibition is against staring at it and examining it closely. The Mishnah Berurah (`ה ק"ס םש) states that one should therefore simply see it and make the Beracha right away.
How often should one recite this Beracha? The Shaarei Teshuvah (`אק"ס םש) rules that although the Gemara in Berachos (:ט"נ ףד) suggests that the Beracha required upon seeing certain things is recited no more than once every thirty days, the Beracha on the rainbow may be recited many times in thirty days because when one sees a rainbow again, it is presumably a new one, since the old one has already disappeared. The Mishnah Berurah (`ב ק"ד םש) accepts this ruling. In the Biur Halacha (האורה ה"דב םש), however, he adds that it is unclear whether one must see the entire rainbow (in the shape of a bow) in order to make the Beracha, or whether seeing a part of it suffices. It would thus seem that because of this doubt, one perhaps should not make the Beracha unless he has seen the entire rainbow.