It was known that there was something dangerous in Moria. Glóin tells the Council of Elrond:
Glóin sighed. ‘Moria! Moria! Wonder of the Northern world! Too deep we delved there, and woke the nameless fear. Long have its vast mansions lain empty since the children of Durin fled. But now we spoke of it again with longing, and yet with dread; for no dwarf has dared to pass the doors of Khazad-dum for many lives of kings, save Thrór only, and he perished.
The Lord of the Rings Book Two, Chapter 2: The Council of Elrond
Page 240 (Houghton Mifflin Harcourt; Single Volume 50th Anniversary Edition)
I don't believe that anyone in Middle Earth was aware that Durin's bane was, in fact a Balrog. In Letter 144, Tolkien writes
The Balrog is a survivor from the Silmarillion and the legends of the First Age. So is Shelob. The Balrogs, of whom the whips were the chief weapons, were primeval spirits of destroying fire, chief servants of the primeval Dark Power of the First Age. They were supposed to have been all destroyed in the overthrow of Thangorodrim, his fortress in the North. But it is here found (there is usually a hang-over especially of evil from one age to another) that one had escaped and taken refuge under the mountains of Hithaeglin (the Misty Mountains). It is observable that only the Elf knows what the thing is – and doubtless Gandalf.
The Letters of JRR Tolkien: Letter 144
We know that Aragorn foresaw that Gandalf would be in danger if he entered Moria. When Gandalf asks who will follow him into Moria, Aragorn warns him
‘I will,’ said Aragorn heavily. ‘You followed my lead almost to disaster in the snow, and have said no word of blame. I will follow your lead now – if this last warning does not move you. It is not of the Ring, nor of us others that I am thinking now, but of you, Gandalf. And I say to you: if you pass the doors of Moria, beware!’
The Lord of the Rings Book Two, Chapter 4: A Journey in the Dark
Page 297 (Houghton Mifflin Harcourt; Single Volume 50th Anniversary Edition)
The fact that Gandalf enters Moria despite the warning doesn't mean he disbelieves it. Celeborn and Galadriel discuss this
‘Alas!’ said Celeborn. ‘We long have feared that under Caradhras a terror slept. But had I known that the Dwarves had stirred up this evil in Moria again, I would have forbidden you to pass the northern borders, you and all that went with you. And if it were possible, one would say that at the last Gandalf fell from wisdom into folly, going needlessly into the net of Moria.’
‘He would be rash indeed that said that thing,’ said Galadriel gravely. ‘Needless were none of the deeds of Gandalf in life. Those that followed him knew not his mind and cannot report his full purpose. But however it may be
with the guide, the followers are blameless.
The Lord of the Rings Book Two, Chapter 7: The Mirror of Galadriel
Page 356 (Houghton Mifflin Harcourt; Single Volume 50th Anniversary Edition)
So we have evidence that Gandalf and Aragorn knew that Gandalf would be in danger in Moria some time before he entered. I haven't found any writing of Tolkien's that confirms that this was meant to happen, but that would be in line with the way major events like this work. In other words, I believe Gandalf was always meant to sacrifice himself, although the details (like the Balrog) may have changed if things had gone otherwise.
While Tolkien dislikes allegory, we can certainly see the parallel between Gandalf's sacrifice and the Christian belief in the (always planned) death and resurrection of Jesus. And it is unlikely that this is accidental.