Kubernetes ingress域名重定向

雪花 发表于: 2019-11-05   最后更新时间: 2019-11-05  

我想在ingress kubernete重定向域名

https://test.example.io/preview/qLxiVcDGxCaQ134650121853FTg4

重定向到

https://test.app.example.io/preview/qLxiVcDGxCaQ134650121853FTg4

我尝试:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    certmanager.k8s.io/cluster-issuer: staging
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
  name: staging-ingress
spec:
  rules:
  - host: test.example.io
    http:
      paths:
      - path: /
        backend:
          serviceName: service-1
          servicePort: 80
      - path: /preview/*
        backend:
          url: 
          serviceName: service-2
          servicePort: 80
  tls:
  - hosts:
    - test.example.io
    secretName: staging

对于简单的nginx block像

location ~ /preview
    {
      rewrite /preview https://test.app.example.com$uri permanent;
    }


您需要解锁本帖隐藏内容请: 点击这里
本帖隐藏的内容




上一条: 如何通过kubernetes selector获取cron job信息
下一条: 怎么在Mac OS Catalina安装minikube?

  • 尝试:

    metadata:
          annotations:
            nginx.ingress.kubernetes.io/configuration-snippet: |
             rewrite /preview https://test.app.example.com$uri permanent;
    spec:
          rules:
          - host: test.example.io
            http:
              paths:
              - path: /
                backend:
                  serviceName: service-1
                  servicePort: 80
          - host: test.app.example.io
            http:
              paths:
              - path: /preview/*
                backend:
                  serviceName: service-2
                  servicePort: 80
    

    在上面的代码中:你不能使用https://test.app.example.io/preview/ (它只是重定向的链接)。