简体   繁体   English

Kube.netes ingress - 访问web服务容器子路径

[英]Kubernetes ingress - access to web service container subpaths

I have a web service ( dashboard-service ) running in a container.我有一个在容器中运行的 web 服务 ( dashboard-service )。 The service provides the required webpages at:该服务在以下位置提供所需的网页:

http://192.168.1.100:3000/page2/ http://192.168.1.100:3000/page2/

http://192.168.1.100:3000/page3/ http://192.168.1.100:3000/page3/

etc ETC

I have the dashboard-service running in a kube.netes cluster, and want to use ingress to control access like this:我在 kube.netes 集群中运行了dashboard-service ,并且想使用入口来控制这样的访问:

so that I can access at: http://192.168.1.100:3000/dashboard/1这样我就可以访问: http://192.168.1.100:3000/dashboard/1

http://192.168.1.100:3000/dashboard/2 http://192.168.1.100:3000/仪表板/2

etc ETC

I've tried the following ingress setup, but am getting "404 Not Found"我尝试了以下入口设置,但收到“404 Not Found”

Is there some way of adding routes to subpaths?有没有办法将路由添加到子路径?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dashboard-service
  namespace: db
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
        - path: /dashboard/
          pathType: Prefix
          backend:
            service:
              name: dashboard-service
              port:
                number: 3000

First of all, there is no below configuration in ingress首先,ingress里面没有下面的配置

  backend:
    service:
      name: dashboard-service
      port:
        number: 3000

You should use next instead..你应该使用 next 代替..

  - backend:
     serviceName: dashboard-service
     servicePort: 3000

Next, I would propose you install, configure and use nginx ingress controller instead of regular kube.netes-ingress.接下来,我建议您安装、配置和使用nginx ingress controller而不是常规的 kube.netes-ingress。 Please note also, if you use nginx controller, your annotation should be nginx.ingress.kube.netes.io/rewrite-target: , not ingress.kube.netes.io/rewrite-target:另请注意,如果您使用 nginx controller,您的注释应为nginx.ingress.kube.netes.io/rewrite-target: ,而不是ingress.kube.netes.io/rewrite-target:

As per NGINX Ingress Controller rewrite documentation , your ingress should look like根据NGINX Ingress Controller 重写文档,您的入口应该看起来像

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /page$2
  name: dashboard-service
  namespace: db
spec:
  rules:
    http:
      paths:
      - backend:
          serviceName: dashboard-service
          servicePort: 3000
        path: /dashboard(/|$)(.*)

I tested regex and capture groups for you here: https://regex101.com/r/3zmz6J/1我在这里为您测试了正则表达式和捕获组: https://regex101.com/r/3zmz6J/1

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

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