There was a link between astronomy and astrology, as @Mauro Allegranza notes but the two things were strictly separated. Ptolemy's Almagest (and his many other scientific books) contains no single word, not even a hint of astrology. On astrology he wrote a separate book, Tetrabiblos. Same applies to other Greek writers on astronomy. No one mixed the two subjects.
To a lesser extent this applies to Muslim astronomers, Brahe and Kepler, but still the two things were usually strictly separated. When one compares
"Astronomia Nova" with astrological writings of Kepler, one has a strong impression that these are works of different authors. Same applies to Ptolemy's books.
I suppose, an explanation of occupation of astronomers by astrology lies in their need to make a living somehow. There was little public demand for pure astronomy,
and very few or no positions where you could earn your living by practicing pure science.
For the same reason, many mathematicians and astronomers until 17 century
practiced medicine (or law). This is my own conjecture, please do not ask for confirming references.
One confirmation of this is an inspection of the web site which is called Math genealogy You see a lot of people whom we remember as scientists
and mathematicians, and who obtained their degree in medicine.
Edit. There is a strong indication, that some of the astronomy and all astrology came to the Greeks from Babylon, after Macedonian conquests.
(Astrology did not exist in Greece before that, and astronomy was rudimentary). How well they were separated in Babylonia, is not clear.
But it seems that they were. At least modern scientists are able to make a clear distinction between astronomical and astrological texts that survive.
Edit 2. In the late Roman empire, public interest to science vanished almost completely and the word "mathematicus" at that time meant "astrologer". Eventually this occupation was simply prohibited by the ban of the Emperor.