You can travel with your Ukrainian passport/ID card to Berlin, Dresden, Nuernberg and Munich. You do not need a ticket.
More Information: https://www.bahn.de/info/helpukraine#en
If you wish to continue your journey, you can get a free “helpukraine” ticket valid in 2nd class to your desired destination at a DB Reisezentrum (DB Travel Centre) or at a DB agency. Please show your Ukrainian ID (passport/ ID card) to the ticket inspector on the train upon request.