k8s~ingress_service_endpoint_pod四壮士 - 张占岭
source link: https://www.cnblogs.com/lori/p/17919788.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
k8s~ingress_service_endpoint_pod四壮士
在Kubernetes中,Service和Endpoints是两个重要的概念,它们之间存在着密切的关系。
-
Service:Service是Kubernetes中用于定义一组Pod的访问方式的抽象。通过创建Service,可以为一组具有相同标签的Pod提供统一的访问入口,使得客户端可以通过Service来访问这些Pod,而无需了解其具体的IP地址和端口号。Service通过标签选择器(selector)来选择匹配的Pod,并将请求转发到这些Pod上。
-
Endpoints:Endpoints是Kubernetes中的另一个资源对象,它存储了与一个Service相关联的实际后端Pod的列表和对应的网络终结点信息(即IP地址和端口号)。当Service被创建时,Kubernetes会自动管理Endpoints对象,将与Service标签选择器匹配的Pod的IP地址和端口号信息存储在Endpoints中。
因此,Service和Endpoints之间的关系可以总结为:Service定义了一组Pod的访问方式
,而Endpoints则存储了这些Pod的实际网络终结点信息
,Service通过Endpoints来实现对后端Pod的负载均衡和代理转发。
ingress,service,endpoints和pod四者关系
在这个示意图中,Ingress定义了对外部流量的访问规则,包括主机名(host)和路径(path)等。Ingress通过指向一个Service来实现流量的转发。Service根据自身的selector选择与之匹配的Pod,并将请求转发到这些Pod上。Endpoints存储了与Service相关联的后端Pod的IP地址和端口信息,而Pod则是应用程序运行的实际容器。
因此,Ingress定义了对外部流量的访问规则,Service提供了对后端Pod的访问入口,Endpoints存储了这些后端Pod的网络终结点信息,而Pod是应用程序实际运行的地方。
endpoint显示的ip是谁的?
Pod在Kubernetes中是有自己的IP地址的,这个IP地址通常由Kubernetes的网络插件(如Calico、Flannel等)负责分配和管理。每个Pod都会被分配一个独立的IP地址,用于在集群内部进行通信。
而Endpoints对象存储的是与Service关联的后端Pod的IP地址和端口信息,它记录了Service需要代理的实际后端Pod的网络终结点信息。Endpoints并不存储所有Pod的IP地址,而是仅存储与特定Service相关联的Pod的IP地址和端口信息。
因此,可以说Pod具有自己的IP地址,并且Endpoints对象存储了与Service相关的Pod的IP地址和端口信息。
- 这是一个pod的信息
[root@lind~]# kubectl describe pod envoy-deployment-786c44794b-rb6wm -n=default
Name: envoy-deployment-786c44794b-rb6wm
Namespace: default
Priority: 0
Node: 192.168.60.1/192.168.60.1
Start Time: Tue, 19 Dec 2023 09:54:24 +0800
Labels: app=envoy
pod-template-hash=786c44794b
workloadID_ingress-10aa232e236bc59c6a7d7d59053154a8=true
workloadID_ingress-c7fdea094d8b2ab0912781e0867ce277=true
Annotations: cattle.io/timestamp: 2023-12-19T01:54:22Z
cni.projectcalico.org/podIP: 10.42.0.150/32
cni.projectcalico.org/podIPs: 10.42.0.150/32
field.cattle.io/ports:
- 这是对应的endpoint的信息
[root@lind~]# kubectl get endpoints -n=default
NAME ENDPOINTS AGE
envoy-service 10.42.0.150:9901,10.42.0.150:10000 70d
- 这是对应的service的信息
[root@lind~]# kubectl get svc -n=default
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
envoy-service NodePort 10.43.189.206 <none> 9901:25568/TCP,10000:13908/TCP 70d
- 这是对应的ingress的信息
[root@lind~]# kubectl get ingress -n=default
NAME CLASS HOSTS ADDRESS PORTS AGE
envoy-final-kc <none> test.xxx.com 192.168.60.2,192.168.60.3,192.168.60.4 80 13d
好了,今天的k8s四壮士的文章就写到这里吧,感谢阅读!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK