在《k8s~Endpoints的使用》文章中,我們知道了如何通過Endpoints來訪問外部資源,而本篇主要說一下它的另一個用法,service的負載均衡,
service的負載pod
service里有個endpoints,它里面存盤所有pod的地址資訊,即請求從外部打到k8s的service的nodeport埠之后(沒有使用clusterIP虛擬ip,而是使用nodeport的方式,ip地址是節點宿主機的,埠也是宿主機的),它會將endpoints串列轉發,而endpionts里存盤的就是每個pod的ip地址,最后落到容器里,
-
通過外部負載均衡器把請求打到 k8s的service里

-
service通過endpoints進行負載,把請求打到具體pod上面

-
查看service資訊,里面只顯示可用的endpoint資訊
[root@elasticsearch02 service-spi]# kubectl describe svc keycloak -n=cas
Name: keycloak
Namespace: pkulaw-cas
Labels: <none>
Annotations: field.cattle.io/publicEndpoints:
[{"addresses":["192.168.3.2"],"port":32080,"protocol":"TCP","serviceName":"cas:keycloak","allNodes":true}]
kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"keycloak","namespace":"cas"},"spec":{"ports":[{"name":"htt...
Selector: app=keycloak
Type: NodePort
IP: 10.43.120.224
Port: http 8080/TCP
TargetPort: 8080/TCP
NodePort: http 32080/TCP
Endpoints: 10.42.1.180:8080,10.42.3.120:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
- 查看endpoints資訊,會區分可用和不可用的Subsets
[root@elasticsearch02 service-spi]# kubectl describe ep keycloak -n=cas
Name: keycloak
Namespace: cas
Labels: <none>
Annotations: <none>
Subsets:
Addresses: 10.42.1.180,10.42.3.120
NotReadyAddresses: 10.42.1.185
Ports:
Name Port Protocol
---- ---- --------
http 8080 TCP
Events: <none>
- k8s~Endpoints的使用
- k8s~Endpoints的使用之負載均衡
作者:倉儲大叔,張占嶺,
榮譽:微軟MVP
QQ:853066980
支付寶掃一掃,為大叔打賞!

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/376882.html
標籤:其他
