Bhagavata Purana consists of the story of Shukdevji reciting to the dying king Parikshit.
Shukdevji was son of sage Vyasa. Sukadeva studied with guru Brihaspati for many years and he became expert at Veda Vedanta. Vyasaji then asked Shukdevji to marry. Sukadeva said, I was born from the Divine Fire, I had a father like Veda Vyasa, and I studied under a Guru like Brihaspati, the Guru of the Gods; I learned for many, many years Veda, Vedanta and now you’re throwing me in to the whirlpool of maya and attachment. Vyasaji informed that as per scriptures, one should go stepwise in life viz. Brahmacharya, Grahasta, Vanaprastha and then Sanyasa. Vyasaji tried to convince him but he refused to marry.
Vyasaji then asked him to go to King Janaka of Mithila for training who is an ocean of wisdom. Shukdevji was keen on learning, but he was doubtful of the knowledge a Palace dwelling king can possess. He was greeted by the guard who said, “Who are you, and what business do you have in our city, and where do you think you are going?”
Shukdevji said, “I’m a Brahmin, I’ve come to see the King, my father sent me, but I don’t think there is any reason to see the King. My father said that I would see the darshan of someone who is known as Videha, He doesn’t have a body, He’s liberated while living, He is a jivanmukta.
Shukdevji thought this man is so bound by attachment; he’s got guards and soldiers standing with weapons around his city saying “Who are you, and what business do you have to enter my door?” No reason to go in at all, I don’t even want to see this guy, I’m going home!”
The guard said, “wait, wait please, I didn’t mean to offend you. It’s just that my job is to stand here and ask everybody. When Janak heard that Shukdevji, his Guru’s son had come to see him, he sent the prime minister. Prime minister greeted Shukdevji and invited him in to the hospitality chambers where he was served delicious food, and he was massaged by beautiful maidens and given a nice bath and given fine clothes to wear and treated like a royal guest. Shukdevji said, I’m a brahmin, I was born from the Divine Fire, I had a father like Veda Vyasa, I had a Guru like Brihaspati. I studied the Vedas for all my life, and here these people are trying to bribe me with beautiful clothes and sumptuous feast and beautiful ladies, I have no desire whatsoever.”
Janakji said, “What is the purpose of your visit here?” Shukdevji said, "My father sent me to you, to learn higher spiritual knowledge, please take me as your student. I must ask you, I don't understand, 'how can a palace dwelling king indulged in the wealth of palace, in the company of queen and children be such a highly recommended Yogi?'"
Janakji said, “Well, you know, it says in our scriptures that a man should be a Brahmacharya, then he becomes a Grahasta, and then he is a Vanaprastha, and then he takes Sanyasa. Shukdevji said, “A man who is bound to a sacrificial pillar could hope for escape, but a man who is bound to care for a wife and family can never hope for escape. How can he flee from the attachments, the bondage to family? I don’t want to get married!”
Janakji said, "We will talk about that later, if you want to be my student, you have to pass a test, take this cup of oil, keep it on your head, go around the palace, keenly observe every room, I will need every detail from you, also you shouldn't spill even a drop of this oil if you want to be my student."
Shukdevji walked into each room of the palace, observed every room in detail and came back in the evening. "O King, I have fulfilled your task." said the young Shukdev.
King Janaka asked many questions to confirm that he had indeed completed his task without fail; King asked Shukdev "How could you observe every room in such detail when you had a full cup of oil on your head?" "I observed every room, but my focus was always on the cup." said Shukdev.
"Same way, though I live in this world performing my duties as a king, husband, father, I always keep my focus on the higher reality." said King Janaka answering Shukdev's earlier question. Janak further said, “I have all of these responsibilities, but none of it is mine. I’m the administrator of this kingdom on behalf of a higher King. I’m only a servant in the kingdom of God. And that’s why they call me liberated while living.”
Sukadeva bowed down to the King, and went back to Veda Vyasa’s house, and said, “Father, Whatever you say, I’m ready to do.” Shukdev got married and he had two children. At the time of marriage, Shukdev was 25 years old. Even after staying in the house of pilgrimage, Shukdev started following the yoga path.
He narrated the story of Srimad Bhagwat to Raja Parikshit, whose testicular serpunition - after examination of death, attained liberation.
While performing duties as Grahasta, one can remain detached and attain liberation.