gpt4 book ai didi

nginx - Nginx入口重写目标不起作用

转载 作者:行者123 更新时间:2023-12-02 12:12:04 24 4
gpt4 key购买 nike

我完全按照这里所说的做了:https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#examples

$ echo '
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: rewrite
namespace: default
spec:
rules:
- host: rewrite.bar.com
http:
paths:
- backend:
serviceName: coffee-svc
servicePort: 80
path: /something(/|$)(.*)
' | kubectl create -f -

创建了入口,我将 rewrite.bar.com添加到了 /etc/hosts中,并将其添加到minikube的ip中。 coffee-svs是此示例中的服务: https://github.com/nginxinc/NGINX-Demos/tree/master/kubernetes-demo-nginx-ingress-resources

但是没有重写发生,我有与此处所示完全相同的用例: Another nginx ingress rewrite-target problem,但是建议的解决方案不起作用。

当我执行 curl rewrite.bar.com/something时,会有一个 404 Not Found响应。

预期的行为是将 rewrite.bar.com/something重写为 rewrite.bar.com/,然后在路径 /上调用coffee-svc。

同样做 curl -I -k rewrite.bar.com/返回:
HTTP/1.1 404 Not Found
Server: nginx/1.17.9
Date: Sat, 02 May 2020 15:24:02 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive

我已经使用 stable/nginx-ingress(当前版本 0.30.0)安装了带有 Helm 的nginx ingress。

Kubernetes的版本是 1.14

编辑:
添加入口 Controller Pod日志
I0502 15:52:00.344425       7 flags.go:215] Watching for Ingress class: nginx
W0502 15:52:00.344820 7 flags.go:260] SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)
W0502 15:52:00.344909 7 client_config.go:543] Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.
I0502 15:52:00.345341 7 main.go:193] Creating API client for https://10.96.0.1:443
I0502 15:52:00.355089 7 main.go:237] Running in Kubernetes cluster version v1.14 (v1.14.1) - git (clean) commit b7394102d6ef778017f2ca4046abbaa23b88c290 - platform linux/amd64
I0502 15:52:00.358184 7 main.go:91] Validated default/my-nginx-ingress-default-backend as the default backend.
I0502 15:52:00.836581 7 main.go:102] SSL fake certificate created /etc/ingress-controller/ssl/default-fake-certificate.pem
W0502 15:52:00.873934 7 store.go:628] Unexpected error reading configuration configmap: configmaps "my-nginx-ingress-controller" not found
I0502 15:52:00.911054 7 nginx.go:263] Starting NGINX Ingress controller
I0502 15:52:02.035037 7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"60b7853f-8c86-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367651", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/rewrite
I0502 15:52:02.113846 7 nginx.go:307] Starting NGINX process
I0502 15:52:02.116614 7 leaderelection.go:242] attempting to acquire leader lease default/ingress-controller-leader-nginx...
I0502 15:52:02.123127 7 controller.go:137] Configuration changes detected, backend reload required.
I0502 15:52:02.135944 7 status.go:86] new leader elected: my-nginx-ingress-controller-6fcc8d7f97-r9d8t
I0502 15:52:02.321762 7 controller.go:153] Backend successfully reloaded.
I0502 15:52:02.321833 7 controller.go:162] Initial sync, sleeping for 1 second.
I0502 15:52:55.451512 7 leaderelection.go:252] successfully acquired lease default/ingress-controller-leader-nginx
I0502 15:52:55.452458 7 status.go:86] new leader elected: my-nginx-ingress-controller-6fcc8d7f97-7p8g6
I0502 15:52:55.470245 7 status.go:274] updating Ingress default/rewrite status from [] to [{10.0.2.15 }]
I0502 15:52:55.475571 7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"60b7853f-8c86-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367750", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress default/rewrite
I0502 15:53:18.288519 7 controller.go:137] Configuration changes detected, backend reload required.
I0502 15:53:18.291422 7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"60b7853f-8c86-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367783", FieldPath:""}): type: 'Normal' reason: 'DELETE' Ingress default/rewrite
I0502 15:53:18.403753 7 controller.go:153] Backend successfully reloaded.
I0502 15:53:20.187998 7 event.go:281] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"rewrite", UID:"0ba43588-8c8d-11ea-b3ad-080027f64399", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"367788", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/rewrite
I0502 15:53:21.623215 7 controller.go:137] Configuration changes detected, backend reload required.
I0502 15:53:21.796798 7 controller.go:153] Backend successfully reloaded.

最佳答案

最后,我通过删除整个minikube集群解决了这个问题:

minikube delete
minikube start

某个地方存在某种影响入口的配置。然后工作正常。 Pitty我不知道罪魁祸首的配置或部署。

关于nginx - Nginx入口重写目标不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61561810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com