[22] 為什麼 EKS 使用 NLB 作為 Kubernetes service 會遇到 connection timeout(二)
EKS 如何註冊 Instance type target group 關聯 Service
在開始之前,我們需要先理解 EKS 環境中, NLB 是如何註冊 EKS worker node 作為 Target Group。先透過 kubectl
查看 Kubernetes Service。
$ kubectl -n nginx-demo describe svc
Name: service-nginx-demo
Namespace: nginx-demo
Labels: <none>
Annotations: service.beta.kubernetes.io/aws-load-balancer-internal: true
service.beta.kubernetes.io/aws-load-balancer-type: nlb
Selector: app=nginx-demo
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.100.135.233
IPs: 10.100.135.233
LoadBalancer Ingress: a0ac38093315243b1a67d275a4379ca6-c09bd862a6e56fc5.elb.eu-west-1.amazonaws.com
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30161/TCP
Endpoints: 192.168.21.160:80,192.168.44.248:80,192.168.73.88:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
由輸出內容 LoadBalancer Ingress endpoint 為 NLB FQDN,使用 NodePort 方式暴露 30161 port。接續,查看在此關聯 NLB 的 Target Group。
$ aws elbv2 describe-target-groups --load-balancer-arn arn:aws:elasticloadbalancing:eu-west-1:111111111111:loadbalancer/net/a0ac38093315243b1a67d275a4379ca6/c09bd862a6e56fc5
{
"TargetGroups": [
{
"TargetGroupArn": "arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/k8s-nginxdem-servicen-f2b581224e/2c5a6b0de24b622d",
"TargetGroupName": "k8s-nginxdem-servicen-f2b581224e",
"Protocol": "TCP",
"Port": 30161,
"VpcId": "vpc-0b150640c72b722db",
"HealthCheckProtocol": "TCP",
"HealthCheckPort": "traffic-port",
"HealthCheckEnabled": true,
"HealthCheckIntervalSeconds": 30,
"HealthCheckTimeoutSeconds": 10,
"HealthyThresholdCount": 3,
"UnhealthyThresholdCount": 3,
"LoadBalancerArns": [
"arn:aws:elasticloadbalancing:eu-west-1:111111111111:loadbalancer/net/a0ac38093315243b1a67d275a4379ca6/c09bd862a6e56fc5"
],
"TargetType": "instance",
"IpAddressType": "ipv4"
}
]
}
$ aws elbv2 describe-target-group-attributes --target-group-arn arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/k8s-nginxdem-servicen-f2b581224e/2c5a6b0de24b622d
{
"Attributes": [
{
"Key": "proxy_protocol_v2.enabled",
"Value": "false"
},
{
"Key": "preserve_client_ip.enabled",
"Value": "true"
},
{
"Key": "stickiness.enabled",
"Value": "false"
},
{
"Key": "deregistration_delay.timeout_seconds",
"Value": "300"
},
{
"Key": "stickiness.type",
"Value": "source_ip"
},
{
"Key": "deregistration_delay.connection_termination.enabled",
"Value": "false"
}
]
}
$ aws elbv2 describe-target-health --target-group-arn arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/k8s-nginxdem-servicen-f2b581224e/2c5a6b0de24b622d --query 'TargetHealthDescriptions[].Target'
[
{
"Id": "i-05cb2efcde4228b34",
"Port": 30161
},
{
"Id": "i-03846c730abe852f4",
"Port": 30161
},
{
"Id": "i-073bba202e9f0119f",
"Port": 30161
},
{
"Id": "i-06bdd562d4fc42c2b",
"Port": 30161
},
{
"Id": "i-020fc35362114539d",
"Port": 30161
}
]
由上述輸出統整,原生 Kubernetes NodePort Service 1 是將 Kubernetes Service port 暴露於每一個 worker上, AWS ELB 整合此特性使用 instance type target group 並將所有 EKS worker node 註冊於同一 Target Group,並由 NodePort 暴露 30161 port 作為對外服務 port。
此外,預設使用 Instance type target group 預設啟用 Client IP preservation 2 target group 屬性。NLB 將會保留原始(source) IP 並轉發至 backend。