1.把端口号对外暴露,通过ip + 端口号进行访问
-
使用Service里面的NodePort实现
2.NodePort缺陷
-
在每个节点都会启动一个端口,在访问时候通过任何节点,通过节点ip+暴露端口号实现访问
-
意味着每个端口只能使用一次,一个端口对应一个应用
-
实际访问中都是使用域名,根据不同域名跳转到不同端口服务中
3.Ingress和Pod关系
-
pod和ingress通过service关联的
-
ingress作为统一入口,由service关联一组pod
-
4.ingress工作流程
5.使用ingress
第一步部署ingress Controller
第二步创建ingress规则
选择官方维护的nginx控制器,实现部署
6.使用Ingress对外暴露应用
(1)创建nginx应用,对外暴露端口使用NodePort
[root@master ~]# kubectl create deployment web3 --image=ngin
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
ds-test-489bb 1/1 Running 0 21h
ds-test-4rvcr 1/1 Running 0 21h
ds-test-nx6kt 1/1 Running 0 21h
hello-1623317280-jd4r2 0/1 Completed 0 2m47s
hello-1623317340-xdw8p 0/1 Completed 0 107s
hello-1623317400-5p22p 0/1 Completed 0 47s
mypod 0/1 Completed 0 21h
tomcat-7d987c7694-kw6xs 1/1 Running 0 21h
web-5bb6fd4c98-9zqzg 1/1 Running 0 21h
web-5bb6fd4c98-d7gqr 1/1 Running 0 21h
web3-587cfc4c49-rgzc9 0/1 ContainerCreating 0 15s
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
ds-test-489bb 1/1 Running 0 21h
ds-test-4rvcr 1/1 Running 0 21h
ds-test-nx6kt 1/1 Running 0 21h
hello-1623317520-rngkw 0/1 Completed 0 2m36s
hello-1623317580-r4bnc 0/1 Completed 0 95s
hello-1623317640-sjhj7 0/1 Completed 0 35s
mypod 0/1 Completed 0 21h
tomcat-7d987c7694-kw6xs 1/1 Running 0 21h
web-5bb6fd4c98-9zqzg 1/1 Running 0 21h
web-5bb6fd4c98-d7gqr 1/1 Running 0 21h
web3-587cfc4c49-rgzc9 1/1 Running 0 4m5s
[root@master ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
tomcat 1/1 1 1 3d21h
web 2/2 2 2 26h
web3 1/1 1 1 4m43s
[root@master ~]# kubectl delete deploy web
deployment.apps "web" deleted
[root@master ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
tomcat 1/1 1 1 3d21h
web3 1/1 1 1 5m11s
[root@master ~]# kubectl expose deployment web3 --port=80 --target-port=80 --type=NodePort#暴露端口
service/web3 exposed
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d21h
web3 NodePort 10.110.237.168 <none> 80:30038/TCP 12s
(2)部署ingress controller
ingress-controller.yaml
apiVersion