You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Minikube部署Tomcat服务后curl请求返回404求助

Troubleshooting Tomcat 404 on Minikube

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:

  1. Check if the Tomcat Pod is running

    kubectl get pods
    

    Look for the pod named tomcat-deployment-<random-string> — its status should be Running. If it's CrashLoopBackOff or Pending, use kubectl describe pod <pod-name> to view startup errors.

  2. Confirm the service is properly exposed

    kubectl get services
    

    You should see tomcat-deployment listed with a NodePort type, and a port in the 30000-32767 range.

  3. 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/html
    

    If 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 22:18:12