ingress 多域名
1. 没有指定host
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
spec:
defaultBackend:
service:
name: test
port:
number: 80
默认这种,没有指定host ,所以访问ip 即可,适合单ingress应用。
NAME CLASS HOSTS ADDRESS PORTS AGE
test-ingress external-lb * 203.0.113.123 80 59s
或者是下面那种通过path来区分请求。
2 通过path来区分:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: simple-fanout-example
spec:
rules:
- host: foo.bar.com
http:
paths:
- path: /foo
pathType: Prefix
backend:
service:
name: service1
port:
number: 4200
- path: /bar
pathType: Prefix
backend:
service:
name: service2
port:
number: 8080
如果是多域名,那么需要指定host
3. 多域名,指定host
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: name-virtual-host-ingress
spec:
rules:
- host: foo.bar.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: service1
port:
number: 80
- host: bar.foo.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: service2
port:
number: 80
4. 小tips
变更完了以后最好用chrome来测试,或者是firefox的隐私窗口,否则缓存会导致怪怪的问题。
详见官网: https://kubernetes.io/docs/concepts/services-networking/ingress/