Ingress 无法从官方 kubernetes 教程运行

Ingress not working from official kubernetes tutorial

我正在关注 this official k8 ingress tutorial。但是我无法 curl minikube IP 地址并访问“网络”应用程序。

minikube addons enable ingress
kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment web --type=NodePort --port=8080
kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml

我能够卷曲 minikube service web --url

的结果
    curl http://127.0.0.1:64671 
    Hello, world!
    Version: 1.0.0
    Hostname: web-79d88c97d6-8z8tc 

但不是通过入口,kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml

(我没有外部 IP - 只有“本地主机”。)

NGG282 kubernetes-ingress % kubectl get ingress
NAME              CLASS   HOSTS   ADDRESS     PORTS   AGE
example-ingress   nginx   *       localhost   80      66m

这似乎是 minikube 的正常现象。尝试卷曲 minikube IP:

curl $(minikube ip)
curl: (7) Failed to connect to 192.168.49.2 port 80: Operation timed out

有什么帮助吗?

------------编辑:

kubectl get deploy -n ingress-nginx -o yaml

          ports:
          - containerPort: 80
            hostPort: 80
            name: http
            protocol: TCP
          - containerPort: 443
            hostPort: 443
            name: https
            protocol: TCP
          - containerPort: 8443
            name: webhook
            protocol: TCP

kubectl get svc -n ingress-nginx -o yaml
apiVersion: v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"name":"ingress-nginx-controller","namespace":"ingress-nginx"},"spec":{"ipFamilies":["IPv4"],"ipFamilyPolicy":"SingleStack","ports":[{"appProtocol":"http","name":"http","port":80,"protocol":"TCP","targetPort":"http"},{"appProtocol":"https","name":"https","port":443,"protocol":"TCP","targetPort":"https"}],"selector":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"type":"NodePort"}}
    creationTimestamp: "2021-12-16T11:41:35Z"
    labels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    name: ingress-nginx-controller
    namespace: ingress-nginx
    resourceVersion: "489"
    uid: 63826bc2-5d90-42f1-861f-f7f082ccf0fb
  spec:
    clusterIP: 10.104.208.171
    clusterIPs:
    - 10.104.208.171
    externalTrafficPolicy: Cluster
    internalTrafficPolicy: Cluster
    ipFamilies:
    - IPv4
    ipFamilyPolicy: SingleStack
    ports:
    - appProtocol: http
      name: http
      nodePort: 30783
      port: 80
      protocol: TCP
      targetPort: http
    - appProtocol: https
      name: https
      nodePort: 30860
      port: 443
      protocol: TCP
      targetPort: https
    selector:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    sessionAffinity: None
    type: NodePort
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"name":"ingress-nginx-controller-admission","namespace":"ingress-nginx"},"spec":{"ports":[{"appProtocol":"https","name":"https-webhook","port":443,"targetPort":"webhook"}],"selector":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"type":"ClusterIP"}}
    creationTimestamp: "2021-12-16T11:41:35Z"
    labels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    name: ingress-nginx-controller-admission
    namespace: ingress-nginx
    resourceVersion: "483"
    uid: fe797532-27c9-4dd1-a1bc-0662a3d2a4da
  spec:
    clusterIP: 10.106.175.35
    clusterIPs:
    - 10.106.175.35
    internalTrafficPolicy: Cluster
    ipFamilies:
    - IPv4
    ipFamilyPolicy: SingleStack
    ports:
    - appProtocol: https
      name: https-webhook
      port: 443
      protocol: TCP
      targetPort: webhook
    selector:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

你需要设置你的 /etc/hosts,我猜入口控制器会等待定义了一个主机的请求来重定向它们,但很奇怪它甚至没有响应错误的 http 请求.

你能显示这些命令的内容吗returns?

kubectl get deploy -n ingress-nginx -o yaml  # only the ports section
kubectl get svc -n ingress-nginx -o yaml

好的,显然这是 known issue with minikube,Ingress 仅在 linux 上正常工作。

The ingress, and ingress-dns addons are currently only supported on Linux. See #7332

您需要在 windows/macOS 上 minikube tunnel 才能 curl,但仍然存在差异:

Windows 上,127.0.0.1localhost 都重定向到应用程序。 在 macOS127.0.0.1localhost 上显示“未找到 nginX”消息,但 curl hello-world.info 仅在更改 etc/hosts 后才有效。