首页 > 技术文章 > k8s 通过 Ingress 访问无状态服务 Nginx

nuo0903 2021-01-28 14:53 原文

无状态服务适用于不需要数据持久化的场景,并且多个实例对统一请求的响应式相同的场景(例如 Nginx、Tomcat 等);

有状态服务适用于需要数据存储功能的服务、或者指多线程类型的服务,队列等 (mysql 数据库、kafka、zookeeper 等)。

 

Ingress 对象可以理解为应用路由,Ingress controller 是应用路由的底层实现。Ingress controller 是跑在 ingress 节点上的。所以想要通过 Ingress 访问无状态服务 nginx, 需要安装 ingress controller 插件,测试的集群需要有 ingress 节点。

 

Ingress 根据请求的主机名和路径将请求转发

 

整个的思路是 ingress --> service --> deployment  --> pod --> container --> nginx

一个外部的请求会通过 ingress 转发到 service,然后再转发到 pod, 再到 pod 里对应的 容器中的 nginx 服务。其中 deployment 根据副本数,对应的控制启动的 pod 的个数

 

 

 

 

ingress 根据host+path,决定使用哪个backend。  backend = service name + service port

 

 

 

 

 

 

 

 

 

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

还可以 describe 查看,更直观

 

 

 

 

 

 

 

推荐阅读