4 Service-LoadBalance
通常需要第三方云提供商支持,有约束性
Ingress
官网:https://kubernetes.io/docs/concepts/services-networking/ingress/
GitHub Ingress Nginx:https://github.com/kubernetes/ingress-nginx
Nginx Ingress Controller:<https://kubernetes.github.io/ingress-nginx/An API object that manages external access to the services in a cluster, typically HTTP. Ingress can provide load balancing, SSL termination and name-based virtual hosting.
Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.
internet
|
[ Ingress ]
--|-----|--
[ Services ]
可以发现,Ingress就是帮助我们访问集群内的服务的。为了彰显其优势,我们在使用Ingress之前,先以一个简单案例出发。
4.1使用NodePort类型的service在K8S集群中部署tomcat
(也为了演示将service写在yaml文件中)
浏览器想要访问这个tomcat,也就是外部要访问该tomcat,用之前的Service-NodePort的方式是可以的,比如暴露一个端口,只需要访问 :即可。
01 创建yaml文件
vim my-tomcat.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment
labels:
app: tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
containers:
- name: tomcat
image: tomcat
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tomcat-

本文通过实战案例,详细介绍了如何在Kubernetes(K8S)集群中利用Ingress资源对象,结合Nginx Ingress Controller,实现对外部HTTP请求的负载均衡、SSL终止及基于名称的虚拟主机托管。通过部署Tomcat服务并创建Ingress规则,成功实现了从外部访问集群内部服务。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



