專一於大數據及容器雲核心技術解密,若有任何學術交流,可隨時聯繫。更多內容請關注《數據雲技術社區》公衆號,或請轉發郵件至1120746959@qq.com。 node
[root@hadoop ~]# kubectl exec productpage-v1-99b4c9954-vj6hf -c istio-proxy -- ps -ef
UID PID PPID C STIME TTY TIME CMD
istio-p+ 1 0 0 03:26 ? 00:00:05
/usr/local/bin/pilot-agent proxy sidecar --domain default.svc.cluster.local
--configPath /etc/istio/proxy
--binaryPath /usr/local/bin/envoy
--serviceCluster productpage.default
--drainDuration 45s --parentShutdownDuration 1m0s
--discoveryAddress istiod.istio-system.svc:15012
--zipkinAddress zipkin.istio-system:9411
--proxyLogLevel=warning
--proxyComponentLogLevel=misc:error
--connectTimeout 10s
--proxyAdminPort 15000
--concurrency 2
--controlPlaneAuthPolicy NONE
--dnsRefreshRate 300s
--statusPort 15020
--trust-domain=cluster.local
--controlPlaneBootstrap=false
istio-p+ 20 1 0 03:26 ? 00:00:21 /usr/local/bin/envoy -c /etc/istio/proxy/envoy-rev0.json
--restart-epoch 0
--drain-time-s 45
--parent-shutdown-time-s 60
--service-cluster productpage.default
--service-node sidecar~10.42.0.69~productpage-v1-99b4c9954-vj6hf.default~default.svc.cluster.local
--max-obj-name-len 189
--local-address-ip-version v4
--log-format [Envoy (Epoch 0)] [%Y-%m-%d %T.%e][%t][%l][%n] %v -l warning
--component-log-level misc:error
--concurrency 2
istio-p+ 36 0 0 06:32 ? 00:00:00 ps -ef
複製代碼
Envoy 支持 靜態(StaticRoute)、 動態(RDS)兩種方式進行路由配置。靜態路由配置,是指寫死在 Envoy 啓動配置文件裏。動態路由配置,又稱 RDS(Route Discovery Service,路由發現服務),是指 Envoy 在運行時向控制面發送請求,由控制面下發路由配置。 從架構圖看出,Envoy的路由機制可粗略劃分爲五步:web
kubectl exec -it productpage-v1-54b8b9f55-bx2dq -c istio-proxy curl http://127.0.0.1:15000/config_dump > config_dump
複製代碼
export PILOT_SVC_IP=$(kubectl -n istio-system get svc -l app=pilot -o go-template='{{range .items}}{{.spec.clusterIP}}{{end}}')
kubectl get pod -l app=productpage
istioctl proxy-config listeners productpage-v1-99b4c9954-vj6hf
ADDRESS PORT TYPE
10.42.0.69 9080 HTTP
10.42.0.69 15020 TCP
10.43.113.103 31400 TCP
10.43.113.103 15443 TCP
10.43.0.1 443 TCP
10.43.86.87 15011 TCP
10.43.39.94 443 TCP
10.43.113.103 443 TCP
10.43.108.37 15012 TCP
10.43.0.10 53 TCP
10.43.86.87 15012 TCP
10.43.86.87 443 TCP
10.43.39.94 15443 TCP
10.43.108.37 443 TCP
10.43.0.10 9153 TCP
10.43.113.103 15020 TCP
10.43.113.103 15031 TCP
10.43.113.103 15032 TCP
10.43.96.17 14250 TCP
0.0.0.0 20001 TCP
0.0.0.0 80 TCP
10.43.113.103 15029 TCP
10.43.96.17 14268 TCP
0.0.0.0 9411 TCP
10.43.113.103 15030 TCP
10.43.96.17 14267 TCP
0.0.0.0 8000 TCP
10.43.34.201 80 TCP
0.0.0.0 15014 TCP
10.43.137.123 443 TCP
0.0.0.0 8080 TCP
0.0.0.0 3000 TCP
10.43.130.148 16686 TCP
0.0.0.0 9090 TCP
0.0.0.0 15010 TCP
0.0.0.0 14250 TCP
0.0.0.0 9080 TCP
0.0.0.0 15001 TCP
0.0.0.0 15006 TCP
0.0.0.0 443 TCP
0.0.0.0 15090 HTTP
istioctl proxy-config listeners productpage-v1-99b4c9954-vj6hf --address 10.43.0.10 --port 53 -o json
{
"name": "envoy.tcp_proxy",
"typedConfig": {
"@type": "type.googleapis.com/envoy.config.filter.network.tcp_proxy.v2.TcpProxy",
"statPrefix": "outbound|53||kube-dns.kube-system.svc.cluster.local",
"cluster": "outbound|53||kube-dns.kube-system.svc.cluster.local",
"accessLog": [
{
"name": "envoy.file_access_log",
"typedConfig": {
"@type": "type.googleapis.com/envoy.config.accesslog.v2.FileAccessLog",
"path": "/dev/stdout",
"format": "[%START_TIME%] \"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\" %RESPONSE_CODE% %RESPONSE_FLAGS% \"%DYNAMIC_METADATA(istio.mixer:status)%\" \"%UPSTREAM_TRANSPORT_FAILURE_REASON%\" %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% \"%REQ(X-FORWARDED-FOR)%\" \"%REQ(USER-AGENT)%\" \"%REQ(X-REQUEST-ID)%\" \"%REQ(:AUTHORITY)%\" \"%UPSTREAM_HOST%\" %UPSTREAM_CLUSTER% %UPSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_REMOTE_ADDRESS% %REQUESTED_SERVER_NAME% %ROUTE_NAME%\n"
}
}
]
}
}
kubectl exec productpage-v1-99b4c9954-vj6hf -c istio-proxy -- netstat -ln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:15090 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:15000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:15001 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:15006 0.0.0.0:* LISTEN
tcp6 0 0 :::15020 :::* LISTEN
9080: productpage進程對外提供的服務端口
15001: Envoy的Virtual Outbound監聽器,iptable會將productpage服務發出的出向流量導入該端口中由Envoy進行處理
15006: Envoy的Virtual Inbound監聽器,iptable會將發到productpage的入向流量導入該端口中由Envoy進行處理
15000: Envoy管理端口,該端口綁定在本地環回地址上,只能在Pod內訪問。
15090:指向127.0.0.1:15000/stats/prometheus, 用於對外提供Envoy的性能統計指標
複製代碼
# 查看 eds
curl http://$PILOT_SVC_IP:8080/debug/edsz|grep "outbound|53||kube-dns.kube-system.svc.cluster.local" -A 27 -B 1
{
"clusterName": "outbound|53||kube-dns.kube-system.svc.cluster.local",
"endpoints": [
{
"lbEndpoints": [
{
"endpoint": {
"address": {
"socketAddress": {
"address": "172.30.135.21",
"portValue": 53
}
}
},
"metadata": {
"filterMetadata": {
"istio": {
"uid": "kubernetes://coredns-64b597b598-4rstj.kube-system"
}
}
}
}
]
},
複製代碼
Envoy 本身實現了一套流量轉發機制, 當訪問 ClusterIP 時,Envoy 就把流量轉發到具體的 Pod 上去,不須要藉助 kube-proxy 的 iptables 或 ipvs 規則docker
curl http://$PILOT_SVC_IP:8080/debug/edsz|grep "outbound|9080||productpage.default.svc.cluster.local" -A 27 -B 1
{
"clusterName": "outbound|9080||productpage.default.svc.cluster.local",
"endpoints": [
{
"locality": {
},
"lbEndpoints": [
{
"endpoint": {
"address": {
"socketAddress": {
"address": "10.42.0.69",
"portValue": 9080
}
}
},
"metadata": {
"filterMetadata": {
"envoy.transport_socket_match": {
"tlsMode": "istio"
}
}
},
"loadBalancingWeight": 1
}
],
"loadBalancingWeight": 1
}
複製代碼
這意味着它將請求交給最符合請求原始目標的監聽器。若是找不到任何匹配的虛擬監聽器,它會將請求發送給返回 404 的 BlackHoleClusterjson
istioctl proxy-config listeners productpage-v1-99b4c9954-vj6hf --port 15001 -o json
[
{
"name": "virtual",
"address": {
"socketAddress": {
"address": "0.0.0.0",
"portValue": 15001
}
},
"filterChains": [
{
"filters": [
{
"name": "envoy.tcp_proxy",
"config": {
"cluster": "BlackHoleCluster",
"stat_prefix": "BlackHoleCluster"
}
}
]
}
],
"useOriginalDst": true
}
]
複製代碼
istioctl proxy-config listeners productpage-v1-99b4c9954-vj6hf --address 0.0.0.0 --port 9080 -o json
"filters": [
{
"name": "envoy.http_connection_manager",
"typedConfig": {
"@type": "type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager",
"statPrefix": "outbound_0.0.0.0_9080",
"rds": {
"configSource": {
"ads": {}
},
"routeConfigName": "9080"
},
複製代碼
istioctl proxy-config routes productpage-v1-99b4c9954-vj6hf --name 9080 -o json
[
{
"name": "9080",
"virtualHosts": [
{
"name": "reviews.default.svc.cluster.local:9080",
"domains": [
"reviews.default.svc.cluster.local",
"reviews.default.svc.cluster.local:9080",
"reviews",
"reviews:9080",
"reviews.default.svc.cluster",
"reviews.default.svc.cluster:9080",
"reviews.default.svc",
"reviews.default.svc:9080",
"reviews.default",
"reviews.default:9080",
"172.21.152.34",
"172.21.152.34:9080"
],
"routes": [
{
"match": {
"prefix": "/"
},
"route": {
"cluster": "outbound|9080||reviews.default.svc.cluster.local",
"timeout": "0.000s"
},
複製代碼
istioctl proxy-config cluster productpage-v1-99b4c9954-vj6hf --fqdn reviews.default.svc.cluster.local -o json
[
{
"name": "outbound|9080||reviews.default.svc.cluster.local",
"type": "EDS",
"edsClusterConfig": {
"edsConfig": {
"ads": {}
},
"serviceName": "outbound|9080||reviews.default.svc.cluster.local"
},
"connectTimeout": "1.000s",
"circuitBreakers": {
"thresholds": [
{}
]
}
}
]
複製代碼
本文核心內容摘自Istio 流量管理實現機制深度解析,爲了加深我的理解,結合實踐,寫了筆記,方便查閱,原文內容請參考:fuckcloudnative.io/posts/istio…後端
專一於大數據及容器雲核心技術解密,若有任何學術交流,可隨時聯繫。更多內容請關注《數據雲技術社區》公衆號,或請轉發郵件至1120746959@qq.com。 api