Kubera(also known as Kuber or Kuvera) is known as the "treasurer of the Gods".How did he get that coveted responsibility? What is the story explaining this?
The Kuber Gayatri Mantra
ॐ यक्षराजय विद्महे वैश्रवणाय धीमहि । तन्नो कुबेर: प्रचोदयात:।।
“Om Yaksharaajaya Vidmahay, Vaishravanaya Dhimahi, Tanno Kubera Prachodayat.”
This means: “We meditate on Kuber, the king of the Yakshas, and son of Vishravana. May that god of wealth inspire and illumine us.” This mantra is often uttered to gain Kuber's blessings in the form of prosperity and acquisition of wealth.
Kuber (also called Kubera or Kuvera), the lord of riches and treasures, is a demi-god in Hinduism.The meaning of the name ‘Kuber’ in Sanskrit is ‘ill-shaped’ or ‘deformed’ although some say that his name is derived from ‘kumba,’
He performed austerities for thousands of years, and received as a boon from Brahmā that he should be the god of riches, and one of the guardians of the world
According to myths, Kuber was Lord Brahma’s mind- born grandson, who deserted his father Vaisravana, and went to his grandfather. Brahma, as a reward made him immortal, and appointed him to be the god of riches, with Lanka for his capital, and the car Pushpak for his Vehicle. See Here
Kubera is often described as a friend of Shiva in the epics. The Padma Purana says that Kubera prayed to Shiva for many years, and Shiva granted him the kingship of Yakshas. See Here
Story of Kubera becoming Lord of wealth is described in Chapter 3 of uttara Khanda of Ramayana.
Vaiśravaṇa (son of viśrava, epithet of Kubera) did Tapasya (penance) for Brahma to become fourth Lokapala.
“The splendorous Vaishravana then went to a forest suitable for the practice of austerities and grew up there like a fire fed oblations of clarified butter. While living in that hermitage, it occurred to the great soul to practice the highest activity of righteousness, for righteousness is the highest goal. While practicing austerities for thousands of years in that great forest, he subdued his senses by severe means and performed the mightiest penances. After the completion of one thousand years, he followed all the appropriate rules, living first on just water, then air, then without anything at all. In that way one thousand years passed as if they were one year.
“Then, accompanied by Lord Indra and hosts of other gods, the highly glorious Lord Brahma came to Vaishravana’s hermitage and spoke the following words: ‘O sage of noble vows, I am very pleased with your actions. O intelligent one, bless you! You deserve a boon. Choose one.’ Vaishravana said to Lord Brahma: ‘O venerable one, I would like to be a loka-pala, a guardian of the world and its protector.’
“With an overjoyed mind, Lord Brahma, in the company of the hosts of gods, said: ‘Yes, I was just about to create the fourth of the loka-palas. Therefore, O knower of right action, go and take the position of lord of wealth in conjunction with Indra, Varuna and Yama. After Indra, Varuna and Yama, you will be the fourth lokapala .
This story might have happened in Vaivasvara Manvantara of Sweta Varaha Kalpa (current Kalpa) as Ramayana happpened in 24th Treta Yuga as per Matsya Purana.
However, a different story is mentioned in Chapter 19 Rudra Samhita (Sristi Khanda) of Shiva Purana which happened in Meghavahana Kalpa.
Gunanidhi, the son of Yajñadatta, performed severe tapas in the city of Kasi. (He performed Tapas just after creation and Shiva didn't move to Kailasa at that time).
Lord Shiva satisfied with his Tapa, manifested before Gunananidhi and conferred him title Lord of wealth by bestowing him treasures.
वरान्ददामि ते वत्स ! तपसाऽनेन तोषितः।
निधीनामथ नाथस्त्वं गुह्यकानां भवेश्वरः॥ २४॥
"O Son, getting pleased with your tapas, I want to give you a boon. You would be the lord of treasures and the Guhyakas.
यक्षाणां किन्नराणां च राज्ञां राजा च सुव्रतः।
पतिः पुण्यजनानां च सर्वेषां धनदो भव॥ २५॥
You would be the king of the kings of Yaksas and Kinnaras. You will be the lord of auspicious people and will bestow riches on all the people.
मया सख्यं च ते नित्यं वत्स्यामि च तवान्तिके।
अलकां निकषा मित्र! तव प्रीतिविवृद्धये॥ २६ ॥
You will always remain friendly with me. I shall always reside close to your city of Alaka, and shall keep on increasing your love for me.
But, Gunananidhi felt jealous on seeing beautiful Goddess Uma and his left eye got burst. He is known by Kubera due to the deformed face.
वत्स ! ते निर्मला भक्तिर्भवे भवतु सर्वदा।
भवैकपिङ्गो नेत्रेण वामेन स्फुटितेन ह।। ३०॥
The goddess said, "O Son, let your spotless devotion in Siva continue forever. You will be deprived of your left eye.
देवेन दत्ता ये तुभ्यं वराः सन्तु तथैव ते।
कुबेरो भव नाम्ना त्वं मम रूपेष्र्यया सुत!।॥ ३१॥
The boons granted to you by Siva shall always be fructuous. You had become jealous of me because of my beauty and because of that you would be called Kubera."
Shiva in human form as Shankara, to stay close to Kubera, thereafter moved to Kailasa mountain which is situated very near to city of Kubera.