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

Kubernetes Ingress路径访问容器失败求助(Minikube环境)

Troubleshooting Your Minikube Ingress Path Access Issue

Hey there! Let's work through this Ingress problem you're having. Since your NodePort services work fine but the path-based Ingress isn't connecting, we can narrow down the issues to a few common culprits. Here's what to check and fix:

1. Verify Minikube's Ingress Addon is Enabled

Minikube doesn't turn on the Ingress controller by default—this is probably the first thing to check.

  • Run this command to see if the ingress addon is active:
    minikube addons list
    
  • If you see ingress: disabled, enable it with:
    minikube addons enable ingress
    
  • Wait a minute or two, then confirm the controller pod is running:
    kubectl get pods -n kube-system
    
    Look for a pod named like nginx-ingress-controller-xxxxxx with a Running status.

2. Fix Path Rewriting for Your Services

Most apps like Portainer and Rancher expect to be served from the root path (/), but your Ingress is routing requests to /portainer and /rancher. Without path rewriting, the service will receive requests at /portainer which it doesn't recognize, leading to 404 errors.

Update your Ingress configuration to add rewrite rules using NGINX annotations. Here's the corrected YAML:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: path-based-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - path: /portainer(/|$)(.*)
        backend:
          serviceName: portainer-service
          servicePort: 80
      - path: /rancher(/|$)(.*)
        backend:
          serviceName: rancher-service
          servicePort: 80
  • The annotation nginx.ingress.kubernetes.io/rewrite-target: /$2 tells the Ingress controller to strip off the /portainer or /rancher prefix before sending the request to the service.
  • The path pattern /portainer(/|$)(.*) matches both /portainer and /portainer/some/subpath, ensuring all related requests get rewritten correctly.

Apply the updated Ingress with:

kubectl apply -f your-ingress-file.yaml

3. Check Ingress Resource Status

Make sure your Ingress is properly configured and linked to your services:

  • Run this command to inspect the Ingress details:
    kubectl describe ingress path-based-ingress
    
  • Look for:
    • No errors in the Events section (like "service not found" or "invalid port").
    • The Address field shows your Minikube IP (you can get this with minikube ip).

4. Test the Ingress Directly

After making these changes, test the access with curl or your browser:

curl http://$(minikube ip)/portainer
curl http://$(minikube ip)/rancher

You should now see the Portainer and Rancher interfaces load correctly.

If you still run into issues, let me know what errors you're seeing (like 404, connection refused) and we can dig deeper!

内容的提问来源于stack exchange,提问作者tienyulin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 00:37:51