首页 > 解决方案 > Ingress-nginx 控制器无法在 AWS EC2 Kubernetes 集群中正确运行 ELB

问题描述

kops我在 AWS EC2 上使用实用程序创建集群。现在我正在尝试配置ingress-nginx控制器,以便它路由集群中的所有流量。我需要它处理 HTTP、HTTPS 和 WebSocket 连接。根据本指南,我做了所有必需的事情:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.28.0/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.28.0/deploy/static/provider/aws/service-l4.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.28.0/deploy/static/provider/aws/patch-configmap-l4.yaml

当我尝试使用以下命令获取ingress-nginx命名空间中的所有项目时kubectl -n ingress-nginx get all

NAME                    TYPE           CLUSTER-IP    EXTERNAL-IP                                                                 PORT(S)                      AGE
service/ingress-nginx   LoadBalancer   100.71.94.9   a7d3fe1383e344c1d8cb2de671xxxxxx-810xxxxxx.eu-central-1.elb.amazonaws.com   80:32389/TCP,443:31803/TCP   16m

当我打开 AWS 控制台 -> EC2 实例 -> 负载均衡器时,我可以看到 ELB 已创建,但OutOfService在“实例”选项卡下的每个节点上都有状态。所以我无法访问我的 ELB URL: a7d3fe1383e344c1d8cb2de671xxxxxx-810xxxxxx.eu-central-1.elb.amazonaws.com:

AWS 控制台 - 负载均衡器 - ELB

有一些关于服务使用的更多细节kubectl -n ingress-nginx describe service/ingress-nginx

Name:                     ingress-nginx
Namespace:                ingress-nginx
Labels:                   app.kubernetes.io/name=ingress-nginx
                          app.kubernetes.io/part-of=ingress-nginx
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout":"60"...
                          service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: 60
                          service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: *
Selector:                 app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/part-of=ingress-nginx
Type:                     LoadBalancer
IP:                       100.71.94.9
LoadBalancer Ingress:     a7d3fe1383e344c1d8cb2de671xxxxxx-810xxxxxx.eu-central-1.elb.amazonaws.com
Port:                     http  80/TCP
TargetPort:               http/TCP
NodePort:                 http  32389/TCP
Endpoints:                <none>
Port:                     https  443/TCP
TargetPort:               https/TCP
NodePort:                 https  31803/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age   From                Message
  ----    ------                ----  ----                -------
  Normal  EnsuringLoadBalancer  15m   service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   15m   service-controller  Ensured load balancer

我错过了什么吗?

UPD #1

如果我在 EKS 集群中做同样的事情,一切都会运行良好,并且入口控制器会出现在每个节点上。有任何想法吗..?

标签: kuberneteskubernetes-ingressnginx-ingresskops

解决方案


您需要在部署了 nginx 的 EC2 实例(kubernetes 工作节点)上添加安全组,以允许为 ELB 创建的安全组使用端口 80 和 443。

编辑:

服务的端点部分service/ingress-nginx没有 nginx pod 的 IP。因此,当 ELB 发送健康检查请求但请求无法到达 Pod 时,健康检查失败并且 ELB 将后端标记为停止服务。


推荐阅读