本文介绍了Kubernetes 入口域重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 nginx 入口 kubernete 中重定向域.

i want to redirect domain in nginx ingress kubernete.

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

如果在 url preview 来改变域重定向

if in url preview comes change domain redirect

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 块就像

for simple nginx block is like

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

推荐答案

我的逻辑思维,试试看:

My logic thinking, try it :

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/(它只是重定向链接).

On code above: You should not access using: https://test.app.example.io/preview/ (It just be redirected link ) at all.

这篇关于Kubernetes 入口域重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-01 13:44