For in the day of trouble He will conceal me in His tabernacle; in the secret place of His tent He will hide me; He will lift me up on a rock.
The secret to King David's public confidence was his private walk with God. He understood that God was protecting and keeping Him.
David had a profound and intimate fellowship with God. The verses before this promise describe David's desire to live in the presence of the Lord.
In Old Testament times, when you had a guest in your home, you were responsible for their protection and provision. Even though it might only be a tent, it became a safe refuge. Your host would lay down his life to make sure you were protected from any attack.
The tabernacle of God is the dwelling place of God. At that time it was just a tent, but David knew there was safety in the presence of God.