Complete a 3 Question Survey and Earn a re:Post Badge
Help improve AWS Support Official channel in re:Post and share your experience - complete a quick three-question survey to earn a re:Post badge!
如何解决 Amazon EKS 中网络负载均衡器的运行不正常的目标?
我想在我的 Amazon Elastic Kubernetes Service(Amazon EKS)中解决网络负载均衡器的运行不正常的目标。
简短描述
下面是网络负载均衡器的目标运行状况不佳的常见原因:
- 运行状况检查配置不正确。
- 容器组(pod)出现意外异常。
- 网络负载均衡器的 externalTrafficPolicy 设置为本地,并在 DHCP 选项上设置了自定义Amazon VPC DNS。
解决方法
验证目标组是 IP 地址还是实例
运行以下命令:
kubectl get service service_name -o yaml
**注意:**请将 service_name 替换为您的服务名称。
如果 service.beta.kubernetes.io/aws-load-balancer-nlb-target-type 注释不存在,则默认目标类型为实例。
验证运行状况检查是否配置正确
检查为您的服务配置了哪些弹性负载均衡(ELB)注释。有关注释的更多信息,请参阅 Kubernetes 网站上的服务(Service)。
运行以下命令来获取注释列表:
kubectl get service service_name -o yaml
输出示例:
service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold: "2"# The number of successive successful health checks required for a backend to be considered healthy for traffic. Defaults to 2, must be between 2 and 10 service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold: "3" # The number of unsuccessful health checks required for a backend to be considered unhealthy for traffic. Defaults to 6, must be between 2 and 10 service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval: "20" # The approximate interval, in seconds, between health checks of an individual instance. Defaults to 10, must be between 5 and 300 service.beta.kubernetes.io/aws-load-balancer-healthcheck-timeout: "5" # The amount of time, in seconds, during which no response means a failed health check. This value must be less than the service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval value. Defaults to 5, must be between 2 and 60 service.beta.kubernetes.io/aws-load-balancer-healthcheck-protocol: TCP service.beta.kubernetes.io/aws-load-balancer-healthcheck-port: traffic-port # can be integer or traffic-port service.beta.kubernetes.io/aws-load-balancer-healthcheck-path: "/" # health check path for HTTP(S) protocols
如果注释配置不正确,则目标可能运行不正常。
从在 Amazon VPC 中运行的主机手动启动运行状况检查
对于实例目标类型,使用 NodePort 运行以下 curl 命令:
curl-ivk node_IP:NodePort
**注意:**请将 node_IP 替换为您的节点的 IP 地址。
对于 IP 地址目标类型,运行以下 curl 命令:
curl -ivk pod_IP:pod_port
**注意:**请将 pod_IP 替换为您的容器组(pod)的 IP 地址。请将 pod_port 替换为应用程序在容器内侦听的端口的名称。
检查容器组(pod)中是否出现意外异常
实例目标类型
-
检查当前运行状况检查配置注释的服务规范。有关完整列表,请参阅 GitHub 网站上的 health check configuration annotations:
kubectl get service service_name -o yaml
-
检查是否有端点来验证服务后面是否有容器组(pod):
kubectl get endpoints service_name -o yaml
-
如果服务不存在端点,请检查容器组(pod)标签和服务标签是否匹配:
kubectl describe servicekubectl describe pod pod_name or kubectl get pod --show-labels
注意: 请将 pod_name 替换为您的容器组(pod)的名称。
-
检查容器组(pod)是否处于正在运行状态:
kubectl get pod -o wide
-
检查容器组(pod)的状态以验证容器组(pod)是否可以在不重启的情况下运行:
kubectl get pods -o wide
-
如果有重启,则收集容器组(pod)日志以确定原因:
kubectl logs pod_namekubectl logs pod_name --previous
-
登录到 Amazon VPC 中的主机,您可以在其中与节点通信。然后,使用带有 NodePort 的 curl 命令来检查容器组(pod)是否返回预期的 HTTP 状态码:
curl node_IP:NodePort
如果 curl 命令未返回预期的 HTTP 状态码,则后端容器组(pod)不会返回预期的 HTTP 状态码。
-
使用同一台主机连接到容器组(pod)的 IP 地址,并检查容器组(pod)的配置是否正确:
curl pod_IP:pod_port
如果 curl 命令未返回预期的 HTTP 状态码,则说明该容器组(pod)的配置不正确。
注意:如果服务的 externalTrafficPolicy(来自 Kubernetes 网站)设置为本地,则只有运行该服务的后端容器组(pod)的节点才会被视为运行正常的目标。
IP 地址目标类型
-
检查当前运行状况检查配置注释的服务规范。有关列表,请参阅 GitHub 网站上的 health check configuration annotations。
kubectl get service service_name -o yaml
-
登录 Amazon VPC 中的主机并使用 curl 命令与容器组(pod)的 IP 地址通信:
curl pod_IP:pod_port
如果 curl 命令未返回预期的 HTTP 状态码,则说明该容器组(pod)的配置不正确。
