Я сделал именно так, как здесь сказано: 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
к IP-адресу minikube. coffee-svs
- это сервис из этого примера: https://github.com/nginxinc/NGINX-Demos/tree/master/kubernetes-demo-nginx-ingress-resources
Пока перезаписи не происходит, у меня точно такой же сценарий использования, как показано здесь: Другой nginx входная задача перезаписи-цели , однако предлагаемое решение не работает.
Когда я выполняю curl rewrite.bar.com/something
, возникает ответ 404 Not Found
.
Ожидаемое поведение будет таким: rewrite.bar.com/something
переписывается как rewrite.bar.com/
и затем вызывается coffee-sv c по пути /
.
Также делает 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
У меня nginx ingress установлен с помощью helm, используя stable/nginx-ingress
, текущая версия 0.30.0
.
Версия Kubernetes: 1.14
.
Редактировать: Добавление журналов ingress-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.