栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Kubernetes 的Ingress的Rewrite annotations

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Kubernetes 的Ingress的Rewrite annotations

1.配置项

2.实验

!!! attention Starting in Version 0.22.0, ingress definitions using the annotation nginx.ingress.kubernetes.io/rewrite-target are not backwards compatible with previous versions. In Version 0.22.0 and beyond, any substrings within the request URI that need to be passed to the rewritten path must explicitly be defined in a capture group.

!!! note Captured groups are saved in numbered placeholders, chronologically, in the form $1, $2 … $n. These placeholders can be used as parameters in the rewrite-target annotation.

Create an Ingress rule with a rewrite annotation:

2.1官方使用
 echo '
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:
      - path: /something(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: http-svc
            port: 
              number: 80
' | kubectl create -f -

In this ingress definition, any characters captured by (.*) will be assigned to the placeholder $2, which is then used as a parameter in the rewrite-target annotation.

For example, the ingress definition above will result in the following rewrites:

rewrite.bar.com/something rewrites to rewrite.bar.com/
rewrite.bar.com/something/ rewrites to rewrite.bar.com/
rewrite.bar.com/something/new rewrites to rewrite.bar.com/new

2.2我的使用
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-lys
  namespace: d1ad16990e484ab7838f5922e1d4b78d
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: "/$1"
spec:
  rules:
  - host: foo.lys.com
    http:
      paths:
      - path: /test/(.*)$
        pathType: Prefix
        backend:
          service:
            name: lys-test-service
            port:
              number: 8081

2.3 参考

https://github.com/kubernetes/ingress-nginx/blob/main/docs/examples/rewrite/README.md

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/395645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号