使用Minikube部署Tomcat服务后curl请求返回404求助
Hey there! Let's break down why you're hitting a 404 when curling your Tomcat service, and fix it step by step.
First: The Most Likely Culprit - Default Tomcat Image Behavior
The official tomcat:9.0 Docker image doesn't have any content in the default ROOT web application directory (/usr/local/tomcat/webapps/ROOT). That means when you curl the base URL (e.g., http://<minikube-ip>:<nodeport>/), Tomcat has nothing to serve, hence the 404.
Quick Test to Confirm This
Instead of curling the root path, try accessing Tomcat's built-in management or documentation endpoints:
# Replace [URL] with the one from minikube service --url curl [URL]/manager/html curl [URL]/docs
You should see the Tomcat manager login page or documentation site (even if you get an auth prompt, that means Tomcat is running correctly).
Verify Your Deployment & Service Are Healthy
Before diving into content issues, let's make sure your Kubernetes resources are working as expected:
Check if the Tomcat Pod is running
kubectl get podsLook for the pod named
tomcat-deployment-<random-string>— its status should beRunning. If it'sCrashLoopBackOfforPending, usekubectl describe pod <pod-name>to view startup errors.Confirm the service is properly exposed
kubectl get servicesYou should see
tomcat-deploymentlisted with aNodePorttype, and a port in the 30000-32767 range.Test Tomcat directly inside the Pod
To rule out networking issues between Minikube and the pod, exec into the running pod and test locally:# Replace <pod-name> with your actual pod name from kubectl get pods kubectl exec -it <pod-name> -- /bin/bash # Inside the pod, run: curl localhost:8080/manager/htmlIf this returns the Tomcat manager page, Tomcat is working fine inside the container — the issue is just missing content at the root path.
Fixing the 404 at Root Path
If you want the base URL to serve content, here are two common approaches:
1. Quick Test: Copy a Static File to the Pod
For a temporary fix, copy a simple index.html file from your local machine to the Tomcat ROOT directory in the pod:
# Create a simple index.html locally first echo "<h1>Hello from Tomcat on Minikube!</h1>" > index.html # Copy it to the pod (replace <pod-name>) kubectl cp index.html <pod-name>:/usr/local/tomcat/webapps/ROOT/index.html
Now curl the base URL again — you should see your new content.
2. Permanent Fix: Build a Custom Tomcat Image
For a production-ready setup, create a custom Docker image that includes your web content or WAR file. Here's a simple Dockerfile example:
FROM tomcat:9.0 # Copy your static files or WAR into the ROOT webapp COPY ./my-web-content/ /usr/local/tomcat/webapps/ROOT/
Build the image, push it to a registry (or use Minikube's local registry with minikube docker-env), then update your deployment.yaml to use this custom image instead of tomcat:9.0.
Double-Check Minikube Networking
If you're still having issues, confirm Minikube's IP is reachable on your Mac:
minikube ip
The URL from minikube service tomcat-deployment --url should use this IP, and you should be able to ping it. If not, restart Minikube with minikube stop && minikube start to reset networking.
内容的提问来源于stack exchange,提问作者Nath

