我有一个在容器中运行的Web服务(dashboard-service
)。该服务在以下位置提供所需的网页:
http://192.168.1.100:3000/page2/
http://192.168.1.100:3000/page3/
等
我有一个dashboard-service
在kubernetes集群中运行,并且想要使用入口来控制访问,如下所示:
以便我可以访问:http://192.168.1.100:3000/dashboard/1
http://192.168.1.100:3000/dashboard/2
等
我尝试了以下入口设置,但收到“ 404未找到”
是否有将路由添加到子路径的方法?
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
答案 0 :(得分:0)
首先,入口中没有下面的配置
backend:
service:
name: dashboard-service
port:
number: 3000
您应该改用next。.
- backend:
serviceName: dashboard-service
servicePort: 3000
接下来,我建议您安装,配置和使用nginx ingress controller而不是常规的kubernetes-ingress。另请注意,如果您使用nginx控制器,则注释应为nginx.ingress.kubernetes.io/rewrite-target:
而不是ingress.kubernetes.io/rewrite-target:
根据NGINX Ingress Controller rewrite documentation,您的进入应该看起来像
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(/|$)(.*)
我在这里为您测试过正则表达式和捕获组:https://regex101.com/r/3zmz6J/1