1 概述
1.1 使用ingress之前
通过端口号对暴露,通过ip+端口号进行访问
在每个节点上面都会启动端口,在访问时通过任何节点,通过节点ip+暴露端口号实现访问
- 意味着每个端口只能使用一次,一个端口对应一个应用
- 实际访问中都是用域名,根据不同域名跳转到不同端口服务中
1.3 Ingress和Pod关系
- pod和ingress通过service关联
- ingress作为统一入口,由service关联一组pod
1.4 ingress工作流程
2 使用ingress
2.1 部署ingress Controller
// 1 创建应用kubectl create deployment web --image=nginx// 2 暴露应用kubectl expose deployment web --port=80 --target-port=80 --type=NodePort// 3 部署ingress Controller// 方法1:拉取镜像需翻墙kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/cloud/deploy.yaml// 4 查看ingress状态kubectl get pods -n ingress-nginx
2.2 创建ingress规则
2.2.1 创建ingress.yaml
apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:name: example-ingressspec:rules:- host: example.ingredemo.comhttp:paths:- path: /backend:serviceName: webserviceProt: 80
2.2.2 执行yaml文件
// 创建应用kubectl apply -f ingress.yaml// 通过浏览器访问
