[问题已处理]-ingress配置导致转发的请求url不一致
k8s
·
导语:近期对公司的k8s进行了升级,同时升级了ingress版本,在使用同一份ingress的规则应用后发现经过ingress转发后前端收到的请求不一致。
有异常的服务器规则如下
请求日志
正常的服务器规则如下
请求日志
对比发现需要在ingress中添加如下规则
nginx.ingress.kubernetes.io/rewrite-target: /
我这里是改了
nginx.ingress.kubernetes.io/rewrite-target: /$1
原规则k8s1.16 nginx-ingress-controller:0.21.0
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"nginx.ingress.kubernetes.io/rewrite-target":"/"},"name":"yitu-ingress","namespace":"yitu"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"mammo-front","servicePort":80},"path":"/mammo_service/"},{"backend":{"serviceName":"chestct-front","servicePort":80},"path":"/lungnodule_service/"},{"backend":{"serviceName":"boneage-front","servicePort":80},"path":"/bone_age/"},{"backend":{"serviceName":"mariner","servicePort":80},"path":"/mariner/"},{"backend":{"serviceName":"mercury","servicePort":80},"path":"/mercury/"},{"backend":{"serviceName":"mars","servicePort":80},"path":"/mars/"},{"backend":{"serviceName":"terra-front","servicePort":80},"path":"/terra/"},{"backend":{"serviceName":"neptune-front","servicePort":80},"path":"/neptune/"},{"backend":{"serviceName":"neptune-api","servicePort":80},"path":"/neptune_api/"},{"backend":{"serviceName":"grafana","servicePort":80},"path":"/grafana/"},{"backend":{"serviceName":"license-validator","servicePort":80},"path":"/license_validator/"},{"backend":{"serviceName":"image-viewer-frontend","servicePort":80},"path":"/imageviewer/"},{"backend":{"serviceName":"chestdr-front","servicePort":80},"path":"/chest_dr/"},{"backend":{"serviceName":"dicom-app","servicePort":80},"path":"/dicom-viewer/"},{"backend":{"serviceName":"studypull-front","servicePort":80},"path":"/study_pull_service/"},{"backend":{"serviceName":"hermes-log-receiver","servicePort":80},"path":"/hermes-log-receiver/"}]}}]}}
nginx.ingress.kubernetes.io/rewrite-target: /
creationTimestamp: "2022-06-28T03:40:08Z"
generation: 26
name: yitu-ingress
namespace: yitu
resourceVersion: "1820730"
selfLink: /apis/extensions/v1beta1/namespaces/yitu/ingresses/yitu-ingress
uid: 61f27398-be81-4ab6-a40c-526662777e90
spec:
rules:
- http:
paths:
- backend:
serviceName: mammo-front
servicePort: 80
path: /mammo_service/
- backend:
serviceName: chestct-front
servicePort: 80
path: /lungnodule_service/
- backend:
serviceName: boneage-front
servicePort: 80
path: /bone_age/
- backend:
serviceName: mariner
servicePort: 80
path: /mariner/
- backend:
serviceName: mercury
servicePort: 80
path: /mercury/
- backend:
serviceName: app-config-front
servicePort: 80
path: /app-config-front/
- backend:
serviceName: terra-api
servicePort: 8001
path: /terra-api/
- backend:
serviceName: terra-front
servicePort: 80
path: /terra/
- backend:
serviceName: neptune-front
servicePort: 80
path: /neptune/
- backend:
serviceName: neptune-api
servicePort: 80
path: /neptune_api/
- backend:
serviceName: grafana
servicePort: 80
path: /grafana/
- backend:
serviceName: license-validator
servicePort: 80
path: /license_validator/
- backend:
serviceName: image-viewer-frontend
servicePort: 80
path: /imageviewer/
- backend:
serviceName: chestdr-front
servicePort: 80
path: /chest_dr/
- backend:
serviceName: dicom-app
servicePort: 80
path: /dicom-viewer/
- backend:
serviceName: studypull-front
servicePort: 80
path: /study_pull_service/
- backend:
serviceName: hermes-log-receiver
servicePort: 80
path: /hermes-log-receiver/
- backend:
serviceName: terra-app-config-bff
servicePort: 8002
path: /bff/
- backend:
serviceName: aiviewer-headless
servicePort: 80
path: /
status:
loadBalancer: {}
现规则k8s1.20 nginx-ingress-controller:v1.1.1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"name":"deepwise-ingress","namespace":"deepwise"},"spec":{"ingressClassName":"nginx","rules":[{"http":{"paths":[{"backend":{"service":{"name":"mammo-front","port":{"number":80}}},"path":"/mammo_service/","pathType":"Prefix"},{"backend":{"service":{"name":"chestct-front","port":{"number":80}}},"path":"/lungnodule_service/","pathType":"Prefix"},{"backend":{"service":{"name":"boneage-front","port":{"number":80}}},"path":"/bone_age/","pathType":"Prefix"},{"backend":{"service":{"name":"mariner","port":{"number":80}}},"path":"/mariner/","pathType":"Prefix"},{"backend":{"service":{"name":"mercury","port":{"number":80}}},"path":"/mercury/","pathType":"Prefix"},{"backend":{"service":{"name":"app-config-front","port":{"number":80}}},"path":"/app-config-front/","pathType":"Prefix"},{"backend":{"service":{"name":"terra-api","port":{"number":8001}}},"path":"/terra-api/","pathType":"Prefix"},{"backend":{"service":{"name":"terra-front","port":{"number":80}}},"path":"/terra/","pathType":"Prefix"},{"backend":{"service":{"name":"neptune-front","port":{"number":80}}},"path":"/neptune/","pathType":"Prefix"},{"backend":{"service":{"name":"neptune-api","port":{"number":80}}},"path":"/neptune_api/","pathType":"Prefix"},{"backend":{"service":{"name":"grafana","port":{"number":80}}},"path":"/grafana/","pathType":"Prefix"},{"backend":{"service":{"name":"license-validator","port":{"number":80}}},"path":"/license_validator/","pathType":"Prefix"},{"backend":{"service":{"name":"image-viewer-frontend","port":{"number":80}}},"path":"/imageviewer/","pathType":"Prefix"},{"backend":{"service":{"name":"chestdr-front","port":{"number":80}}},"path":"/chest_dr/","pathType":"Prefix"},{"backend":{"service":{"name":"dicom-app","port":{"number":80}}},"path":"/dicom-viewer/","pathType":"Prefix"},{"backend":{"service":{"name":"studypull-front","port":{"number":80}}},"path":"/study_pull_service/","pathType":"Prefix"},{"backend":{"service":{"name":"hermes-log-receiver","port":{"number":80}}},"path":"/hermes-log-receiver/","pathType":"Prefix"},{"backend":{"service":{"name":"terra-app-config-bff","port":{"number":8002}}},"path":"/bff/","pathType":"Prefix"},{"backend":{"service":{"name":"aiviewer-headless","port":{"number":80}}},"path":"/","pathType":"Prefix"}]}}]}}
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/use-regex: "true"
creationTimestamp: "2022-08-11T08:07:41Z"
generation: 17
managedFields:
- apiVersion: networking.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:kubectl.kubernetes.io/last-applied-configuration: {}
f:spec:
f:ingressClassName: {}
manager: kubectl-client-side-apply
operation: Update
time: "2022-08-11T08:07:41Z"
- apiVersion: networking.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
f:nginx.ingress.kubernetes.io/rewrite-target: {}
f:nginx.ingress.kubernetes.io/use-regex: {}
f:spec:
f:rules: {}
manager: kubectl-edit
operation: Update
time: "2022-08-15T13:25:47Z"
name: deepwise-ingress
namespace: deepwise
resourceVersion: "566745"
uid: d579e690-877f-4eda-8743-6b359dbdf9a6
spec:
ingressClassName: nginx
rules:
- http:
paths:
- backend:
service:
name: mammo-front
port:
number: 80
path: /mammo_service/(.+)
pathType: Prefix
- backend:
service:
name: chestct-front
port:
number: 80
path: /lungnodule_service/(.+)
pathType: Prefix
- backend:
service:
name: boneage-front
port:
number: 80
path: /bone_age/(.+)
pathType: Prefix
- backend:
service:
name: mariner
port:
number: 80
path: /mariner/(.+)
pathType: Prefix
- backend:
service:
name: mercury
port:
number: 80
path: /mercury/(.+)
pathType: Prefix
- backend:
service:
name: app-config-front
port:
number: 80
path: /app-config-front/(.+)
pathType: Prefix
- backend:
service:
name: app-config-front
port:
number: 80
path: /app-config-front/
pathType: Prefix
- backend:
service:
name: terra-api
port:
number: 8001
path: /terra-api/(.+)
pathType: Prefix
- backend:
service:
name: terra-front
port:
number: 80
path: /terra/(.+)
pathType: Prefix
- backend:
service:
name: neptune-front
port:
number: 80
path: /neptune/(.+)
pathType: Prefix
- backend:
service:
name: neptune-api
port:
number: 80
path: /neptune_api/(.+)
pathType: Prefix
- backend:
service:
name: grafana
port:
number: 80
path: /grafana/(.+)
pathType: Prefix
- backend:
service:
name: license-validator
port:
number: 80
path: /license_validator/(.+)
pathType: Prefix
- backend:
service:
name: image-viewer-frontend
port:
number: 80
path: /imageviewer/(.+)
pathType: Prefix
- backend:
service:
name: chestdr-front
port:
number: 80
path: /chest_dr/(.+)
pathType: Prefix
- backend:
service:
name: dicom-app
port:
number: 80
path: /dicom-viewer/(.+)
pathType: Prefix
- backend:
service:
name: studypull-front
port:
number: 80
path: /study_pull_service/(.+)
pathType: Prefix
- backend:
service:
name: hermes-log-receiver
port:
number: 80
path: /hermes-log-receiver/(.+)
pathType: Prefix
- backend:
service:
name: terra-app-config-bff
port:
number: 8002
path: /bff/(.+)
pathType: Prefix
- backend:
service:
name: aiviewer-headless
port:
number: 80
path: /?(.*)
pathType: Prefix
status:
loadBalancer:
ingress:
- ip: 100.64.40.5
这里测试path: /bff?(.*)
等于/bff/(.+)
加上/bff/
更多推荐
已为社区贡献84条内容
所有评论(0)