The Encyclopedia of Arda does not clear things up. But how did a creature that could go toe to toe (to toe to toe to toe etc) with the most powerful Ainur come into being?
While not stated explicitly in JRRT’s writings it was implied, and, I always believed Ungoliant to be another renegade Ainur, but one who forsook the music to pursue her own ends in the Little Kingdom.
From The Silmarillion:
“There, beneath the sheer walls of the mountains and the cold dark sea, the shadows were deepest and thickest in the world; and there in Avathar, secret and unknown, Ungoliant had made her abode. The Eldar knew not whence she came; but some have said that in ages long before she descended from the darkness that lies about Arda, when Melkor first looked down in envy upon the Kingdom of Manwë, and that in the beginning she was one of those that he corrupted to his service.”
Since she came from outside Arda, that pretty much makes her Ainur.