Kubernetes 入口规则:如何同时使用通配符和特定子域
Kubernetes ingress rules: How to use wildcard and specific subdomain together
我希望 Ingress 将特定子域重定向到一个后端,并将所有其他子域重定向到另一个后端。基本上,我想定义如下规则:
If subdomain is foo.bar.com
then go to s1
, for all other subdomains go to s2
当我在 Ingress 规范中如下所示定义规则时,我在部署时遇到此异常:
Error: UPGRADE FAILED: cannot re-use a name that is still in use
当我将 *.bar.com
更改为 demo.bar.com
时,它起作用了。
这是我的 Ingress 资源规范:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
spec:
rules:
- host: foo.bar.com
http:
paths:
- backend:
serviceName: s1
servicePort: 80
- host: *.bar.com
http:
paths:
- backend:
serviceName: s2
servicePort: 80
有人知道是否可行吗?
我很确定目前在查看问题 41881, but I could be missing something in the most recent version of Kubernetes—we're about to release 1.12 时这是不可能的。
已经提出了支持入口规则中的通配符域的 PR。
参考下面link
https://github.com/containous/traefik/issues/3884
你能试试 Traefik v1.7 看看是否启用了通配符支持。
您可以使用默认后端 -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
spec:
- backend:
serviceName: s2
servicePort: 80
rules:
- host: foo.bar.com
http:
paths:
- backend:
serviceName: s1
servicePort: 80
现在可以在 Kubernetes:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: nginx
kubernetes.io/ingress.global-static-ip-name: web-static-ip
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/server-alias: www.foo.bar
nginx.ingress.kubernetes.io/use-regex: "true"
name: foo-bar-ingress
namespace: test
spec:
rules:
- host: 'foo.bar.com'
http:
paths:
- backend:
serviceName: specific-service
servicePort: 8080
path: /(.*)
pathType: ImplementationSpecific
- host: '*.bar.com'
http:
paths:
- backend:
serviceName: general-service
servicePort: 80
path: /(.*)
pathType: ImplementationSpecific
我希望 Ingress 将特定子域重定向到一个后端,并将所有其他子域重定向到另一个后端。基本上,我想定义如下规则:
If subdomain is
foo.bar.com
then go tos1
, for all other subdomains go tos2
当我在 Ingress 规范中如下所示定义规则时,我在部署时遇到此异常:
Error: UPGRADE FAILED: cannot re-use a name that is still in use
当我将 *.bar.com
更改为 demo.bar.com
时,它起作用了。
这是我的 Ingress 资源规范:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
spec:
rules:
- host: foo.bar.com
http:
paths:
- backend:
serviceName: s1
servicePort: 80
- host: *.bar.com
http:
paths:
- backend:
serviceName: s2
servicePort: 80
有人知道是否可行吗?
我很确定目前在查看问题 41881, but I could be missing something in the most recent version of Kubernetes—we're about to release 1.12 时这是不可能的。
已经提出了支持入口规则中的通配符域的 PR。 参考下面link
https://github.com/containous/traefik/issues/3884
你能试试 Traefik v1.7 看看是否启用了通配符支持。
您可以使用默认后端 -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
spec:
- backend:
serviceName: s2
servicePort: 80
rules:
- host: foo.bar.com
http:
paths:
- backend:
serviceName: s1
servicePort: 80
现在可以在 Kubernetes:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: nginx
kubernetes.io/ingress.global-static-ip-name: web-static-ip
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/server-alias: www.foo.bar
nginx.ingress.kubernetes.io/use-regex: "true"
name: foo-bar-ingress
namespace: test
spec:
rules:
- host: 'foo.bar.com'
http:
paths:
- backend:
serviceName: specific-service
servicePort: 8080
path: /(.*)
pathType: ImplementationSpecific
- host: '*.bar.com'
http:
paths:
- backend:
serviceName: general-service
servicePort: 80
path: /(.*)
pathType: ImplementationSpecific