I have read bhagavad gita where krishna mentions maya to be a illusion and everything in this is world is made of maya. What I don't understand is if everything is made up of maya then why is krishna telling it, isn't that too maya ? and what about the moksha, isn't that also a delusion? Why should I still try to attain moksha if it is unreal?
Everything that we see and don't see, the whole of our material existence is made up of two primary components, prakriti and purusha:
Of these two, prakruti is the inert and insentient part and purusha is the active sentient part. So all lifeless matter that we see starting from sand grains to matter in our bodies is the product of prakruti. But the other part known as Purusha is what gives life to matter. So we living beings are a marveolous fusion of prakruti and purusha. And it is this prakruti which is also known as maya, avidya (ignorance), etc.:
Now the thing regarding maya is that, due to its influence the soul which is actually free finds itself in bondage. Mind is the product of prakriti, hence it naturally stays under the influence of the threefold material natures known as satva, rajas and tamas. These threefold nature arise due to prakriti or maya:
And because the mind of a person naturally stays under its influence, he does many kinds of material activities and gets entangled and bound in the samsara. Due to his actions under the influence of God's maya he keeps on wandering through different bodies:
But, beyond this material existence there exists spiritual existence entering where one doesn't have to return to this material world of pain and suffering again:
So because jiva is primarily spiritual in nature but has accepted this material mode of existence due to ignorance (maya), Shri Kirshna instructs to get rid of it and try for liberation.
Why does maya exist?
It exists because God exists. Just like heat and light are inherent properties of fire, maya is an inherent energy potential of God. Hence, it will always exist. So no one can destroy it completely, but can get rid of it for himself. So Shri Krishna says:
So the answers to your questions are as below:
Thus I have briefly answered your questions. But the subject matter is such that it can occupy a whole book. But to summarize all, I end the answer with the following verse:
"Māyā" means "reality"
It can also mean "illusion", depending on your viewpoint. Literally, "mā" "yā" — that, which is not. Lord Krišna is the only puruša and īšvara or total enjoyer and controller above all states of existence (BG 4.6, 5.29). For all other, there are basically two states of reality — yoga māyā (BG 7.25) and mahā māyā (BG 7.26-27).
or parā prakriti facilitates the pastimes of the living entities in the spiritual world in connection with their (our) source (BG 9.13).
or aparā prakriti covers the full knowledge and constrains to material dualities of sense perception. This isolates those who do not cooperate with their source (BG 9.12).
Most of the Vedic instructions are about switching your perception of reality from material to transcendental, e.g. Bhagavad-gītā 7.28. The transcendental reality is supposed to be more enjoyable. However, it can still be called illusion, because someone like Nada babā might think he is the father of Krishna, although actually Krishna is the original source and Nanda is actually His energy. Nonetheless, that relationship is extremely enjoyable for both of them.
can also be created by mystic beings like rākšasas, and people can also bewilder each other. Every woman is supposed to somewhat possess mystic abilities. These illusions can also be called "māyā", but they are not so general and permanent.
Under the influence of the three gunas, the soul is (1) misled by matter, and (2) subsequently entangled and entrapped. This tendency is termed maya (illusion).
Under maya's influence, the atman, (the soul) mistakenly identifies with the body. He accepts such thoughts as "I am white and I am a man," or "This is my house, my country, and my religion." Thus the illusioned soul identifies with the temporary body and everything connected to it, such as race, gender, family, nation, bank balance, and sectarian religion. Under this sense of false-ego (false-identity) the soul aspires to control and enjoy matter. However, in so doing he continuously serves lust, greed, and anger. In frustration he often redoubles his efforts and, compounding mistake upon mistake, only falls deeper into illusion.
In ignorance (tamas), he is fully convinced that right is wrong and wrong is right. In passion he is unsure, hesitant, sometimes enjoying and at others times repenting. Only in goodness does the soul begin to develop wisdom – to see things in the real light. Thus enlightenment means moving away from tamas towards sattva. By so doing, the soul gradually escapes the clutches of maya and moves towards liberation.
You are confused about maya (illusion) and moksha (liberation from material world). Krishna says this material world is illusion becasue if I ask you a simple question you won't be able to answer it. If I ask you to point towards you then you can point towards your face, your chest, your head and etc etc etc but none of it is you. Those are all basically the organs of your material body. So where is that real you located? Most of the world is deluded about it and instead most focus is on gross material body which is not the real self. But the soul is very subtle. It is covered by gross material body and astral body and both are the covering of soul in material worlds. This is illusion. This is the illusion which has been covering the soul in material world. And Krishna tells us how to remove that illusion. But moksha is real thing. It is not illusion. It is removal of illusion. It is important and you should strive for it because if not then illusion will keep you in material world in different bodies. This material world is actually a prison house and we are not supposed to be here eternally. Our real home is in Golok Vrindavan, the abode of God himself.