Spring Boot部署至Azure出现Internal Server Error求助
Let's break down this issue step by step—there are a few common culprits that cause an Internal Server Error when deploying a Spring Boot app to Kubernetes on Azure. Here's how to diagnose and fix them:
First, rule out issues with your Docker image itself. Run it locally to see if the app responds correctly:
docker run -p 8090:8090 <your-image-name>
Then hit http://localhost:8090 in your browser or use curl. If this fails, the problem is with your Docker setup, not Kubernetes/Azure.
Check your Dockerfile for red flags
Looking at your Dockerfile, a couple of things stand out:
- Hardcoded absolute paths: You're copying the JAR to
/Users/a/Documents/dev/intellij/dockerImages/—this path won't exist in a clean Java 8 container! Use a generic path like/appinstead:FROM java:8 COPY ./springsimple-1.0-SNAPSHOT.jar /app/ WORKDIR /app EXPOSE 8090 CMD ["java", "-jar", "springsimple-1.0-SNAPSHOT.jar"] - Confirm the JAR is in the build context: When you run
docker build, make sure you're in the directory wherespringsimple-1.0-SNAPSHOT.jarlives, otherwise theCOPYcommand will fail silently (checkdocker buildlogs for errors). - Check your Spring Boot app's port: Does your app actually listen on 8090? By default Spring Boot uses 8080. If you haven't set
server.port=8090inapplication.propertiesorapplication.yml, yourEXPOSEdirective is pointing to the wrong port.
If the local Docker run works, the issue is in your Kubernetes deployment. Let's check the Pod status and logs:
- Get the list of Pods:
kubectl get pods
Look for the testproject Pod—its status should be Running. If it's CrashLoopBackOff or Error, that means the container is failing to start.
- View the Pod logs to see what's going wrong:
kubectl logs testproject
This will show you the Spring Boot startup logs, which will tell you if there's an error loading the app, missing dependencies, or port conflicts.
- Check the Pod's details for any runtime issues:
kubectl describe pod testproject
Look at the Events section at the bottom—this will show if there were issues pulling the image from your registry, or if the container failed to start.
If your Pod is running but you get an Internal Server Error when accessing it, make sure your Kubernetes Service is pointing to the correct port. For example, if you created a Service with:
kubectl expose deployment testproject --type=LoadBalancer --port=80 --target-port=8090
Double-check that target-port matches the port your Spring Boot app is listening on. If you used the default 8080, change target-port to 8080.
- Network Security Group (NSG) rules: Make sure the NSG associated with your Kubernetes cluster allows inbound traffic on the port you're using (8090 or 8080, plus the Service port if using LoadBalancer).
- Ingress configuration (if used): If you're using an Ingress controller, ensure the routing rules are pointing to the correct Service and port.
- Fix your Dockerfile to use a non-hardcoded path and confirm the JAR is in the build context.
- Verify your Spring Boot app's port matches what's in
EXPOSEand your Kubernetes Service. - Check Pod logs for startup errors—this is almost always the quickest way to find the root cause.
内容的提问来源于stack exchange,提问作者marhg

