简体   繁体   English

Kubernetes Nginx Ingress pod 子路径

[英]Kubernetes Nginx Ingress pod subpath

I have a pod that exposes an HTTP service.我有一个暴露 HTTP 服务的 pod。
This pod has some HTTP endpoints which are available under /accounts .这个 pod 有一些 HTTP 端点,可以在/accounts
My goal is to access this sub-path via accounts.example.com .我的目标是通过accounts.example.com访问这个子路径。

For example if the url accounts.example.com/test is requested, the nginx ingress should route the request to /accounts/test on my pod.例如,如果请求 url accounts.example.com/test入口应该将请求路由到我的 pod 上的/accounts/test

In the nginx ingress documentation I cannot find a use-case with examples like this.在 nginx 入口文档中,我找不到包含此类示例的用例。

You should use rewrite to accomplish your request.您应该使用重写来完成您的请求。

https://kubernetes.github.io/ingress-nginx/examples/rewrite/https://kubernetes.github.io/ingress-nginx/examples/rewrite/

  • Here is an example:下面是一个例子:
    • Focus on this line: path: /something(/|$)(.*)关注这一行: path: /something(/|$)(.*)
apiVersion: networking.k8s.io/v1
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: http-svc
          servicePort: 80
        path: /something(/|$)(.*)

  • Look on the different annotations for the re-write:查看重写的不同注释:

在此处输入图片说明 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM