My teacher called me ugly today. What should I do?
First, that is not appropriate! Teachers should never insult their students, even if they're frustrated with them. It sounds like you might have a few options for how to handle this situation.
You could try to speak to your teacher one-on-one and let them know that what they said was hurtful and out of line. Unfortunately, there is a power dynamic in place that gives them some authority over you. This can be intimidating and might possibly provoke your teacher to be even harder on you. Of course, it is possible that your teacher regrets what they said and would like to apologize to you. Consider your teacher's average personality-- how do you think the situation would go if you approached them?
Alternately, you could go to your school principal, dean, or counselor and let them know what's happened. There is a possibility that if your teacher has spoken harshly with you, they are speaking harshly with other students. This is a serious issue which creates a hostile environment in the classroom, and no school wants that to be the case. Telling someone who works at your school will help resolve your particular case and possibly prevent it from happening to anyone else.
You might also consider telling your parents or a friend. Having someone who can advocate for you and speak to your principal (or dean, or school counselor) could remove some of the stress from your mind. I think that, at least, you should discuss this situation with someone close to you who can have your back if need be.
I understand that you are worried about the punishment your teacher might receive, and I want to say that it's very honorable of you to consider their feelings even though they've hurt you. If it is of some comfort, your teacher may not be fired from their position but could be reprimanded in other ways. I do not know for sure your school's policy on such matters. Even if your teacher is fired from their position with your school, they could find a job elsewhere. (In many parts of the world, the school year is coming to a close, so perhaps they could find a new job over the summer if they are indeed fired.)
Please remember that you have the option to remain anonymous in this situation. If you choose to speak to your principal in person, you can ask that your name not be used in any discussion of this matter. A friend might be able to speak on your behalf without using your name. Or you could write a letter to your principal explaining the issue and signing it anonymously.