Mainly answering the Qn in title, from the analytic perspective.
According go Swami Sachhidananda from Gujarat (no English or web source for this), the serpent related to the deities or gods have to be interpreted as possibly awakened Kundalini.
Different spiritual traditions teach methods of "awakening" kundalini for the purpose of reaching spiritual enlightenment and a range of supernormal powers. Writer Joseph Campbell describes the concept of Kundalini as “the figure of a coiled female serpent—a serpent goddess not of "gross" but of "subtle" substance - which is to be thought of as residing in a torpid, slumbering state in a subtle center, the first of the seven, near the base of the spine: the aim of the yoga then being to rouse this serpent, lift her head, and bring her up a subtle nerve or channel of the spine to the so-called “thousand-petaled lotus” (Sahasrara) at the crown of the head
According to Kundalini Yoga:
The Sanskrit adjective kuṇḍalin means "circular, annular". It does occur as a noun for "a snake" (in the sense "coiled", as in "forming ringlets")
Kundalini is believed to be an energy resting inside the bottom of the body in a snake like coiled form. When it is awakened, it starts moving upwards. This is the prime reason, behind drawing the Gods in certain ways with snake & sometimes lotus:
Lord Vishnu represented as supreme Brahman in form of entirety. Who rests on [awakened or not] Kundalini energy in form of Adi Shesha; This is the ultimate Kundalini of the whole universe. As per Gita, all the creation comes out from the nature (SwabhAva) of the supreme self (Atma/"Me"). Hence, Vishnu at times is shown relaxing on the resting Adi Shesha; as of the whole universe is being dreamt by Vishnu

Goddess Earth is resting on the serpent; This represent's Earth's own Kundalini as a deity
[no image]
Lord Shankara's (Rudra from Himalaya) Kundalini is always awakened due to his continuous penance

Lord Krishna who defeated Kaliya, was a symbolic story created, to express that, at the tender age of six-seven years, Krishna got his Kundalini energy awaken towards the self realisation
