You do not need any military experience to become an astronaut. Among other things you will need "A bachelor's degree in engineering, biological science, physical science, computer science or mathematics".
More info can be found here https://www.nasa.gov/audience/forstudents/postsecondary/features/F_Astronaut_Requirements.html
- Military experience is not a requirement to be an astronaut, however it can be used to complete one of the requirements to become one. One of the requirements is "At least three years of related professional experience obtained after degree completion OR at least 1,000 hours pilot-in-command time on jet aircraft." Military experience can help with the 1000 hours of pilot time.