[英]NGINX Ingress 404 not found using docker desktop on windows (not minikube)
我正在嘗試使這個基本示例在 Windows 上的 docker 桌面上工作,我沒有使用 minikube: https ://kubernetes.github.io/ingress-nginx/deploy/
我設法使用 NodePort 訪問該服務:http://localhost:31429
但是當我嘗試“http://hello-world.info”(確保將它添加到主機中)時,找不到 404。
kubectl get svc --all-namespaces NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 20m default web NodePort 10.111.220.81 <none> 8080:31429/TCP 6m47s ingress-nginx ingress-nginx-controller LoadBalancer 10.107.29.182 localhost 80:30266/TCP,443:32426/TCP 19m ingress-nginx ingress-nginx-controller-admission ClusterIP 10.101.138.244 <none> 443/TCP 19m kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 20m kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE example-ingress <none> hello-world.info 80 21m
我迷路了,有人可以幫忙嗎? 我還注意到 ADDRESS 是空的。
非常感謝。
在 Docker Desktop 4.1.1、Windows 10 Pro 上重現此案例
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.4/deploy/static/provider/cloud/deploy.yaml
據我了解,@dev1334 使用了在 Minikube 上設置 Ingress 和 NGINX Ingress Controller文章中的示例。 我還嘗試了對原始示例進行了一些修改。
在spec.rules
部分的example-ingress.yaml
文件的example-ingress.yaml
中,指定了主機hello-world.info
。 由於 Docker Desktop for Windows 在安裝過程中添加到C:\\Windows\\System32\\drivers\\etc\\hosts
中的主機文件,因此以下條目: 127.0.0.1 kubernetes.docker.internal
我從hello-world.info
更改了example-ingress.yaml
的主機hello-world.info
到kubernetes.docker.internal
但是由於以下錯誤,Ingress 仍然沒有按預期工作: "Ignoring ingress because of error while validating ingress class" ingress="default/example-ingress" error="ingress does not contain a valid IngressClass"
我將這一行kubernetes.io/ingress.class: "nginx"
到example-ingress.yaml
的注釋部分
因此, example-ingress.yaml
文件的最終版本如下。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: kubernetes.docker.internal
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
- path: /v2
pathType: Prefix
backend:
service:
name: web2
port:
number: 8080
檢測結果
C:\Users\Andrew_Skorkin>kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default web-79d88c97d6-c8xnf 1/1 Running 0 112m
default web2-5d47994f45-cxtzm 1/1 Running 0 94m
ingress-nginx ingress-nginx-admission-create-sjdcq 0/1 Completed 0 114m
ingress-nginx ingress-nginx-admission-patch-wccc9 0/1 Completed 1 114m
ingress-nginx ingress-nginx-controller-5c8d66c76d-jb4w9 1/1 Running 0 114m
...
C:\Users\Andrew_Skorkin>kubectl get svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d15h
default web NodePort 10.101.43.157 <none> 8080:32651/TCP 114m
default web2 NodePort 10.100.4.84 <none> 8080:30081/TCP 96m
ingress-nginx ingress-nginx-controller LoadBalancer 10.106.138.217 localhost 80:30287/TCP,443:32664/TCP 116m
ingress-nginx ingress-nginx-controller-admission ClusterIP 10.111.208.242 <none> 443/TCP 116m
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 7d15h
C:\Users\Andrew_Skorkin>curl kubernetes.docker.internal
Hello, world!
Version: 1.0.0
Hostname: web-79d88c97d6-c8xnf
C:\Users\Andrew_Skorkin>curl kubernetes.docker.internal/v2
Hello, world!
Version: 2.0.0
Hostname: web2-5d47994f45-cxtzm
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.