apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-test
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: my.nginx.test
http:
paths:
- path: /hello-world
backend:
serviceName: hello-world-svc
servicePort: 80
- path: /hello-k8s
backend:
serviceName: hello-k8s-svc
servicePort: 8080
[root@vm10-0-11-170 ~]# kubectl apply -f ingress.yaml
ingress.extensions/nginx-test created
[root@vm10-0-11-170 ~]# kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
nginx-test my.nginx.test 80 15s
这里我们将自有域名my.nginx.test解析到负载均衡的IP。
Ingress规则与nginx-ingress-controller的对应关系通过注解kubernetes.io/ingress.class: nginx来指定,表示此条ingress规则由nginx-ingress-controller处理。