Nginx配置:
location /api {
proxy_pass http://192.168.10.200:9091/app/api;
}
在上面示例中,当我们访问 /api,将会转发到后端服务 /app/api 接口,用ingress实现此配置如下
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /app/api/$1
creationTimestamp: "2023-12-27T09:46:24Z"
generation: 10
name: appapi-ing
namespace: prod
resourceVersion: "22394071"
uid: 4574597b-b784-472a-8bc2-27f218809658
spec:
ingressClassName: nginx
rules:
- host: api.xxx.com
http:
paths:
- backend:
service:
name: appapi
port:
number: 9091
path: /api/(.*)
pathType: Prefix