gpt4 book ai didi

nginx - Kubernetes NGINX 入口重写目标注释中断

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

我在 docker desktop for windows 下运行 kubernetes v1.16。我已经使用 helm 安装了 nginx-ingress Controller v1.7.9。我已更新我的主机文件以具有以下条目127.0.0.1 application.local我有一个名为 hedgehog-service 的后端服务.
以下入口定义正确地将请求转发到后端。

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ml-zoo-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: application.local
http:
paths:
- path: /hedgehog/
backend:
serviceName: hedgehog-service
servicePort: 80
curl application.local/hedgehog按预期工作并命中后端服务。
但是,为了正确使用后端服务,我需要重写目标,删除 url 前缀 /hedgehog .因此我有以下入口定义
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ml-zoo-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: application.local
http:
paths:
- path: /hedgehog(/|$)(.*)
backend:
serviceName: hedgehog-service
servicePort: 80
如此处所示: https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target
现在当我 curl application.local/hedgehog/test入口 Controller 不与后端通信,但根据日志尝试打开文件
2020/06/23 12:46:48 [error] 708#708: *792 open() "/etc/nginx/html/hedgehog/test" failed (2: No such file or directory), client: 192.168.65.3, server: application.local, request: "GET /hedgehog/test HTTP/1.1", host: "application.local"
192.168.65.3 - - [23/Jun/2020:12:46:48 +0000] "GET /hedgehog/test HTTP/1.1" 404 153 "-" "curl/7.65.3" "-"
这里是 etc/nginx/conf.d/default-ml-zoo-ingress的内容
# configuration for default/ml-zoo-ingress

upstream default-ml-zoo-ingress-application.local-hedgehog-service-80 {
zone default-ml-zoo-ingress-application.local-hedgehog-service-80 256k;
random two least_conn;

server 10.1.0.48:80 max_fails=1 fail_timeout=10s max_conns=0;
}

server {
listen 80;
server_tokens on;
server_name application.local;

location /hedgehog(/|$)(.*) {

proxy_http_version 1.1;
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
client_max_body_size 1m;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering on;

proxy_pass http://default-ml-zoo-ingress-application.local-hedgehog-service-80;

}
}

有谁知道为什么我的 URL 没有被重写并且请求被传递到后端服务?
提前致谢!

最佳答案

好吧,玩了几个小时,一旦我写了这个问题,我的下一个谷歌就会找到答案。
我使用 helm 安装了 nginx,带有以下 repo stable/nginx-ingress .但是根据这个问题 https://github.com/kubernetes/ingress-nginx/issues/5756这实际上是一个遗留存储库。我卸载了我的 Controller 并将存储库更改为 ingress-nginx

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
一切似乎都按预期工作。仍然不确定为什么以前的 Controller 安装失败但我可以重新开始工作:)

EDIT: For the aid of others that might end up here - in hindsight I am wondering if the reinstallation simply meant that I deleted and recreated my ingress which might have solved the original problem. In other words make sure you try recreating the ingress before reinstalling the ingress controller with helm.

关于nginx - Kubernetes NGINX 入口重写目标注释中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62535281/

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