Based on nginx -> traefik -> k8s architecture, an application needs to support a large number of business any custom domain name, Zezheng it? Application of this scenario we encountered on the company k8s, so the research under the following two scenarios:
Scenario 1, the most direct and brutal but very lowB program, ingress listed for each domain name
# more ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: zhanghao-custom
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: aa.xx.com
http:
paths:
- path: /service
backend:
serviceName: zhanghao-gateway-www
servicePort: http
- path: /
backend:
serviceName: zhanghao-web
servicePort: http
- host: bb.yy.com
http:
paths:
- path: /service
backend:
serviceName: zhanghao-gateway-www
servicePort: http
- path: /
backend:
serviceName: zhanghao-web
servicePort: http
Each new domain name, we must modify ingress, can not be accepted.
Method 2: traefik new entryPoint, ingress at the request of wild entryPoint
nginx control of non-custom domain name to go traefik_normal, custom domain name to go zhanghao_custom
upstream traefik_normal {
server traefik_server1:80;
server traefik_server2:80;
}
upstream zhanghao_custom {
server traefik_server1:81;
server traefik_server2:81;
}
traefik default is all requests go entryPoints: http (80 ports), add a custom domain name entryPoints: zhanghao-custom (81 ports)
# more traefik.toml
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.zhanghao-custom]
address = ":81"
ingress custom domain annotations provided by walking entryPoints: zhanghao-custom (81 ports); not specified host, receive requests all domain names;
Add custom domain configuration does not need to move, once and for all
# more ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: zhanghao-custom
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/frontend-entry-points: zhanghao-custom
spec:
rules:
- http:
paths:
- path: /service
backend:
serviceName: zhanghao-gateway-www
servicePort: http
- path: /
backend:
serviceName: zhanghao-web
servicePort: http
traefik effect is as follows:
over!