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

Ubuntu下Docker驱动Minikube的Ingress无法访问问题求助

在Ubuntu的Docker驱动Minikube中通过Ingress访问服务失败的排查与解决

系统及Minikube详情

Ubuntu系统版本:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:    22.04
Codename:   jammy

Minikube运行状态正常:

$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

Minikube采用Docker驱动,启动日志:

$ minikube start
😄  minikube v1.32.0 on Ubuntu 22.04
✨  Using the docker driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🏃  Updating the running docker "minikube" container ...
🐳  Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                      │
│    Registry addon with docker driver uses port 32780 please use that instead of default port 5000    │
│                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯
📘  For more information see: https://minikube.sigs.k8s.io/docs/drivers/docker
    ▪ Using image docker.io/registry:2.8.3
    ▪ Using image gcr.io/k8s-minikube/kube-registry-proxy:0.0.5
🔎  Verifying registry addon...
🌟  Enabled addons: default-storageclass, storage-provisioner, registry
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

集群已部署资源

$ kubectl get all
NAME                         READY   STATUS    RESTARTS        AGE
pod/mysvc-54cdf74f4f-kmn44   1/1     Running   17 (6m5s ago)   137m

NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/kubernetes     ClusterIP   10.96.0.1        <none>        443/TCP    3h54m
service/mysvc          ClusterIP   10.107.181.101   <none>        5000/TCP   137m

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/mysvc   1/1     1            1           137m

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/mysvc-54cdf74f4f   1         1         1       137m

Ingress配置

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: local-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: mysvc.k2.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: mysvc 
            port:
              number: 80

本地配置及访问尝试

Minikube节点IP:

$ minikube ip
192.168.49.2

已在/etc/hosts添加域名映射:

192.168.49.2 mysvc.k2.local

启动minikube tunnel并完成sudo授权:

$ minikube tunnel
✅  Tunnel successfully started

📌  NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...

❗  The service/ingress local-ingress requires privileged ports to be exposed: [80 443]
🔑  sudo permission will be asked for it.
🏃  Starting tunnel for service local-ingress.
[sudo] password for osuser: 

查看Ingress状态:

$ kubectl get ingress local-ingress
NAME            CLASS    HOSTS          ADDRESS   PORTS   AGE
local-ingress   <none>   mysvc.k2.local             80      35m
$ kubectl describe ingress local-ingress
Name:             local-ingress
Labels:           <none>
Namespace:        default
Address:          
Ingress Class:    <none>
Default backend:  <default>
Rules:
  Host          Path  Backends
  ----          ----  --------
  mysvc.k2.local  
                /   mysvc:80 ()
Annotations:    nginx.ingress.kubernetes.io/rewrite-target: /
Events:         <none>

访问失败情况:

$ curl mysvc.k2.local
^C 
$ ping mysvc.k2.local
PING mysvc.k2.local (192.168.49.2) 56(84) bytes of data.
^C
--- mysvc.k2.local ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1032ms

后续操作记录

编辑1:初始启用Ingress插件失败

$ minikube addons list | grep ingress
| ingress                     | minikube | disabled     | Kubernetes                     |
| ingress-dns                 | minikube | disabled     | minikube                       |
$ minikube addons enable ingress
💡  ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.
You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
    ▪ Using image registry.k8s.io/ingress-nginx/controller:v1.9.4
    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0
    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0
🔎  Verifying ingress addon...

❌  Exiting due to MK_ADDON_ENABLE: enable failed: run callbacks: running callbacks: [waiting for app.kubernetes.io/name=ingress-nginx pods: context deadline exceeded]

╭───────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                           │
│    😿  If the above advice does not help, please let us know:                             │
│    👉  https://github.com/kubernetes/minikube/issues/new/choose                           │
│                                                                                           │
│    Please run `minikube logs --file=logs.txt` and attach logs.txt to the GitHub issue.    │
│    Please also attach the following file to the GitHub issue:                             │
│    - /tmp/minikube_addons_ee0e2a5ffa0c23cbbbf48fa0fc668431256e65f3_0.log                  │
│                                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────╯

编辑2:先后启用ingress-dns和ingress插件成功

$ minikube addons enable ingress-dns
💡  ingress-dns is an addon maintained by minikube. For any concerns contact minikube on GitHub.
You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
    ▪ Using image gcr.io/k8s-minikube/minikube-ingress-dns:0.0.2
🌟  The 'ingress-dns' addon is enabled
$ minikube addons enable ingress
💡  ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.
You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
    ▪ Using image registry.k8s.io/ingress-nginx/controller:v1.9.4
    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0
    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0
🔎  Verifying ingress addon...
🌟  The 'ingress' addon is enabled

疑问

现在除了已启动的minikube tunnel,还需要做什么才能正常访问服务?


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 06:34:57